tag');
this.assertElement(this.firstChild, { tagName: 'div', content: '' });
};
_class5.prototype.assertContent = function assertContent(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() {
(0, _emberBabel.classCallCheck)(this, TrustedContentTest);
return (0, _emberBabel.possibleConstructorReturn)(this, _DynamicContentTest5.apply(this, arguments));
}
TrustedContentTest.prototype.assertIsEmpty = function assertIsEmpty() {
this.assert.strictEqual(this.firstChild, null);
};
TrustedContentTest.prototype.assertContent = function assertContent(content) {
this.assertHTML(content);
};
TrustedContentTest.prototype.assertStableRerender = function assertStableRerender() {
var _this27 = this;
this.takeSnapshot();
this.runTask(function () {
return _this27.rerender();
});
_DynamicContentTest5.prototype.assertInvariants.call(this);
};
TrustedContentTest.prototype.assertInvariants = function assertInvariants() {
// 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() {
(0, _emberBabel.classCallCheck)(this, _class6);
return (0, _emberBabel.possibleConstructorReturn)(this, _TrustedContentTest.apply(this, arguments));
}
_class6.prototype.renderPath = function renderPath(path) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.render('{{{' + path + '}}}', context);
};
_class6.prototype['@test updating trusted curlies'] = function testUpdatingTrustedCurlies() {
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() {
(0, _emberBabel.classCallCheck)(this, _class7);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.apply(this, arguments));
}
_class7.prototype['@test it can render a dynamic template'] = function testItCanRenderADynamicTemplate() {
var _this31 = this;
var template = '\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 ';
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 ';
var react = '\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.render(template, {
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(react);
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 testItShouldEvaluateToNothingIfPartOfThePathIsUndefined() {
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 testItShouldEvaluateToNothingIfPartOfThePathIsAPrimative() {
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 testCanSetDynamicHref() {
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 testQuotelessClassAttributesUpdateCorrectly() {
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 testQuotedClassAttributesUpdateCorrectly(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 testUnquotedClassAttributeCanContainMultipleClasses() {
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 testUnquotedClassAttribute() {
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 testQuotedClassAttribute() {
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 testQuotedClassAttributeCanContainMultipleClasses() {
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 testClassAttributeConcatsBoundValues() {
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 testClassAttributeAcceptsNestedHelpersAndUpdates() {
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 testMultipleDynamicClasses() {
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 testClassesAreOrderedSeeIssue9912() {
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() {
(0, _emberBabel.classCallCheck)(this, 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 teardown() {
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 assertStyleWarning(style) {
this.assert.deepEqual(warnings, [(0, _emberViews.constructStyleDeprecationMessage)(style)]);
};
StyleTest.prototype.assertNoWarning = function assertNoWarning() {
this.assert.deepEqual(warnings, []);
};
return StyleTest;
}(_testCase.RenderingTest);
(0, _testCase.moduleFor)('Inline style tests', function (_StyleTest) {
(0, _emberBabel.inherits)(_class8, _StyleTest);
function _class8() {
(0, _emberBabel.classCallCheck)(this, _class8);
return (0, _emberBabel.possibleConstructorReturn)(this, _StyleTest.apply(this, arguments));
}
_class8.prototype['@test can set dynamic style'] = function testCanSetDynamicStyle() {
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 testCanSetDynamicStyleWithHtmlSafe() {
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() {
(0, _emberBabel.classCallCheck)(this, _class9);
return (0, _emberBabel.possibleConstructorReturn)(this, _StyleTest2.apply(this, arguments));
}
_class9.prototype['@test specifying
generates a warning'] = function testSpecifyingDivStyleUserValueDivGeneratesAWarning(assert) {
var userValue = 'width: 42px';
this.render('
', {
userValue: userValue
});
this.assertStyleWarning(userValue);
};
_class9.prototype['@test specifying `attributeBindings: ["style"]` generates a warning'] = function testSpecifyingAttributeBindingsStyleGeneratesAWarning(assert) {
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 testSpecifyingDivStyleUserValueDivWorksProperlyWithoutAWarning(assert) {
this.render('
', {
userValue: 'width: 42px'
});
this.assertNoWarning();
};
_class9.prototype['@test specifying `
` works properly with a SafeString'] = function testSpecifyingDivStyleUserValueDivWorksProperlyWithASafeString(assert) {
this.render('
', {
userValue: new _helpers.SafeString('width: 42px')
});
this.assertNoWarning();
};
_class9.prototype['@test null value do not generate htmlsafe warning'] = function testNullValueDoNotGenerateHtmlsafeWarning(assert) {
this.render('
', {
userValue: null
});
this.assertNoWarning();
};
_class9.prototype['@test undefined value do not generate htmlsafe warning'] = function testUndefinedValueDoNotGenerateHtmlsafeWarning(assert) {
this.render('
');
this.assertNoWarning();
};
_class9.prototype['@test no warnings are triggered when using `-html-safe`'] = function testNoWarningsAreTriggeredWhenUsingHtmlSafe(assert) {
this.render('
', {
userValue: 'width: 42px'
});
this.assertNoWarning();
};
_class9.prototype['@test no warnings are triggered when a safe string is quoted'] = function testNoWarningsAreTriggeredWhenASafeStringIsQuoted(assert) {
this.render('
', {
userValue: new _helpers.SafeString('width: 42px')
});
this.assertNoWarning();
};
_class9.prototype['@test binding warning is triggered when an unsafe string is quoted'] = function testBindingWarningIsTriggeredWhenAnUnsafeStringIsQuoted(assert) {
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 testBindingWarningIsTriggeredWhenASafeStringForACompletePropertyIsConcatenatedInPlace(assert) {
var userValue = 'width: 42px';
this.render('
', {
userValue: new _helpers.SafeString('width: 42px')
});
this.assertStyleWarning('color: green; ' + userValue);
};
_class9.prototype['@test binding warning is triggered when a safe string for a value is concatenated in place'] = function testBindingWarningIsTriggeredWhenASafeStringForAValueIsConcatenatedInPlace(assert) {
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 testBindingWarningIsTriggeredWhenASafeStringForAPropertyNameIsConcatenatedInPlace(assert) {
var userValue = 'width';
this.render('
', {
userProperty: new _helpers.SafeString(userValue)
});
this.assertStyleWarning('color: green; ' + userValue + ': 42px');
};
return _class9;
}(StyleTest));
}
});
QUnit.module('ESLint | ember-glimmer/tests/integration/content-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/content-test.js should pass ESLint\n\n');
});
enifed('ember-glimmer/tests/integration/custom-component-manager-test', ['ember-babel', '@glimmer/runtime', 'ember-glimmer/tests/utils/test-case', 'ember/features', 'ember-glimmer'], function (_emberBabel, _runtime, _testCase, _features, _emberGlimmer) {
'use strict';
if (_features.GLIMMER_CUSTOM_COMPONENT_MANAGER) {
var TestLayoutCompiler = function () {
function TestLayoutCompiler(template) {
(0, _emberBabel.classCallCheck)(this, TestLayoutCompiler);
this.template = template;
}
TestLayoutCompiler.prototype.compile = function compile(builder) {
builder.wrapLayout(this.template);
builder.tag.dynamic(function () {
return _runtime.PrimitiveReference.create('p');
});
builder.attrs.static('class', 'hey-oh-lets-go');
builder.attrs.static('manager-id', 'test');
};
return TestLayoutCompiler;
}();
var TestComponentManager = function (_AbstractComponentMan) {
(0, _emberBabel.inherits)(TestComponentManager, _AbstractComponentMan);
function TestComponentManager() {
(0, _emberBabel.classCallCheck)(this, TestComponentManager);
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractComponentMan.apply(this, arguments));
}
TestComponentManager.prototype.create = function create(env, definition, args, dynamicScope, caller, hasBlock) {
return definition.ComponentClass.create();
};
TestComponentManager.prototype.layoutFor = function layoutFor(definition, bucket, env) {
return env.getCompiledBlock(TestLayoutCompiler, definition.template);
};
return TestComponentManager;
}(_emberGlimmer.AbstractComponentManager);
(0, _testCase.moduleFor)('Components test: curly components with custom manager', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test it can render a basic component with custom component manager'] = function testItCanRenderABasicComponentWithCustomComponentManager(assert) {
var managerId = 'test';
this.owner.register('component-manager:' + managerId, new TestComponentManager());
this.registerComponent('foo-bar', {
template: '{{use-component-manager "' + managerId + '"}}hello',
managerId: managerId
});
this.render('{{foo-bar}}');
assert.equal(this.firstChild.className, 'hey-oh-lets-go', 'class name was set correctly');
assert.equal(this.firstChild.tagName, 'P', 'tag name was set correctly');
assert.equal(this.firstChild.getAttribute('manager-id'), managerId, 'custom attribute was set correctly');
};
return _class;
}(_testCase.RenderingTest));
}
});
QUnit.module('ESLint | ember-glimmer/tests/integration/custom-component-manager-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/custom-component-manager-test.js should pass ESLint\n\n');
});
enifed('ember-glimmer/tests/integration/event-dispatcher-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal', 'ember/features', 'ember-views'], function (_emberBabel, _testCase, _helpers, _emberMetal, _features, _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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test events bubble view hierarchy for form elements'] = function testEventsBubbleViewHierarchyForFormElements(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 events bubble to parent view'] = function testEventsBubbleToParentView(assert) {
var _this3 = this;
var receivedEvent = void 0;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
change: function (event) {
receivedEvent = event;
}
}),
template: '{{yield}}'
});
this.registerComponent('x-bar', {
ComponentClass: _helpers.Component.extend({
change: function () {}
}),
template: '
'
});
this.render('{{#x-foo}}{{x-bar}}{{/x-foo}}');
this.runTask(function () {
return _this3.$('#is-done').trigger('change');
});
assert.ok(receivedEvent, 'change event was triggered');
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
};
_class.prototype['@test events bubbling up can be prevented'] = function testEventsBubblingUpCanBePrevented(assert) {
var _this4 = this;
var hasReceivedEvent = void 0;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
change: function () {
hasReceivedEvent = true;
}
}),
template: '{{yield}}'
});
this.registerComponent('x-bar', {
ComponentClass: _helpers.Component.extend({
change: function () {
return false;
}
}),
template: '
'
});
this.render('{{#x-foo}}{{x-bar}}{{/x-foo}}');
this.runTask(function () {
return _this4.$('#is-done').trigger('change');
});
assert.notOk(hasReceivedEvent, 'change event has not been received');
};
_class.prototype['@test dispatches to the nearest event manager'] = function testDispatchesToTheNearestEventManager(assert) {
var _this5 = this;
var receivedEvent = void 0;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function (event) {
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 _this5.$('#is-done').trigger('click');
});
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
};
_class.prototype['@test event manager can re-dispatch to the component'] = function testEventManagerCanReDispatchToTheComponent(assert) {
var _this6 = 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 _this6.$('#is-done').trigger('click');
});
assert.deepEqual(handlers, ['eventManager', 'component']);
};
_class.prototype['@test event handlers are wrapped in a run loop'] = function testEventHandlersAreWrappedInARunLoop(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() {
(0, _emberBabel.classCallCheck)(this, _class2);
var _this7 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.call(this));
var dispatcher = _this7.owner.lookup('event_dispatcher:main');
(0, _emberMetal.run)(dispatcher, 'destroy');
_this7.owner.__container__.reset('event_dispatcher:main');
_this7.dispatcher = _this7.owner.lookup('event_dispatcher:main');
return _this7;
}
_class2.prototype['@test additional events can be specified'] = function testAdditionalEventsCanBeSpecified(assert) {
this.dispatcher.setup({ myevent: 'myEvent' });
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
myEvent: function () {
assert.ok(true, 'custom event was triggered');
}
}),
template: '
Hello!
'
});
this.render('{{x-foo}}');
this.$('div').trigger('myevent');
};
_class2.prototype['@test eventManager is deprecated'] = function testEventManagerIsDeprecated(assert) {
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 a rootElement can be specified'] = function testARootElementCanBeSpecified(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 testDefaultEventsCanBeDisabledViaCustomEvents(assert) {
this.dispatcher.setup({ click: null });
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function () {
assert.ok(false, 'click method was called');
},
null: function () {
assert.ok(false, 'null method was called');
},
doubleClick: function () {
assert.ok(true, 'a non-disabled event is still handled properly');
}
}),
template: '
Hello!
'
});
this.render('{{x-foo}}');
this.$('div').trigger('click');
this.$('div').trigger('dblclick');
};
_class2.prototype['@test throws if specified rootElement does not exist'] = function testThrowsIfSpecifiedRootElementDoesNotExist(assert) {
var _this8 = this;
assert.throws(function () {
_this8.dispatcher.setup({ myevent: 'myEvent' }, '#app');
});
};
return _class2;
}(_testCase.RenderingTest));
(0, _testCase.moduleFor)('custom EventDispatcher subclass with #setup', function (_RenderingTest3) {
(0, _emberBabel.inherits)(_class3, _RenderingTest3);
function _class3() {
(0, _emberBabel.classCallCheck)(this, _class3);
var _this9 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.call(this));
var dispatcher = _this9.owner.lookup('event_dispatcher:main');
(0, _emberMetal.run)(dispatcher, 'destroy');
_this9.owner.__container__.reset('event_dispatcher:main');
_this9.owner.unregister('event_dispatcher:main');
return _this9;
}
_class3.prototype['@test canDispatchToEventManager is deprecated in EventDispatcher'] = function testCanDispatchToEventManagerIsDeprecatedInEventDispatcher(assert) {
var MyDispatcher = _emberViews.EventDispatcher.extend({
canDispatchToEventManager: null
});
this.owner.register('event_dispatcher:main', MyDispatcher);
expectDeprecation(/`canDispatchToEventManager` has been deprecated/);
this.owner.lookup('event_dispatcher:main');
};
return _class3;
}(_testCase.RenderingTest));
if (_features.EMBER_IMPROVED_INSTRUMENTATION) {
(0, _testCase.moduleFor)('EventDispatcher - Instrumentation', function (_RenderingTest4) {
(0, _emberBabel.inherits)(_class4, _RenderingTest4);
function _class4() {
(0, _emberBabel.classCallCheck)(this, _class4);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest4.apply(this, arguments));
}
_class4.prototype.teardown = function teardown() {
_RenderingTest4.prototype.teardown.call(this);
(0, _emberMetal.instrumentationReset)();
};
_class4.prototype['@test instruments triggered events'] = function testInstrumentsTriggeredEvents(assert) {
var clicked = 0;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function (evt) {
clicked++;
}
}),
template: '
hello
'
});
this.render('{{x-foo}}');
this.$('div').trigger('click');
assert.equal(clicked, 1, 'precond - the click handler was invoked');
var clickInstrumented = 0;
(0, _emberMetal.instrumentationSubscribe)('interaction.click', {
before: function () {
clickInstrumented++;
assert.equal(clicked, 1, 'invoked before event is handled');
},
after: function () {
clickInstrumented++;
assert.equal(clicked, 2, 'invoked after event is handled');
}
});
var keypressInstrumented = 0;
(0, _emberMetal.instrumentationSubscribe)('interaction.keypress', {
before: function () {
keypressInstrumented++;
},
after: function () {
keypressInstrumented++;
}
});
this.$('div').trigger('click');
this.$('div').trigger('change');
assert.equal(clicked, 2, 'precond - The click handler was invoked');
assert.equal(clickInstrumented, 2, 'The click was instrumented');
assert.strictEqual(keypressInstrumented, 0, 'The keypress was not instrumented');
};
return _class4;
}(_testCase.RenderingTest));
}
if (canDataTransfer) {
(0, _testCase.moduleFor)('EventDispatcher - Event Properties', function (_RenderingTest5) {
(0, _emberBabel.inherits)(_class5, _RenderingTest5);
function _class5() {
(0, _emberBabel.classCallCheck)(this, _class5);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest5.apply(this, arguments));
}
_class5.prototype['@test dataTransfer property is added to drop event'] = function testDataTransferPropertyIsAddedToDropEvent(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 _class5;
}(_testCase.RenderingTest));
}
});
QUnit.module('ESLint | ember-glimmer/tests/integration/event-dispatcher-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/event-dispatcher-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test casts binding to dasherized class'] = function testCastsBindingToDasherizedClass() {
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 testsCastsLeafPathOfBindingToDasherizedClass() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/-class-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/-class-test.js should pass ESLint\n\n');
});
enifed('ember-glimmer/tests/integration/helpers/closure-action-test', ['ember-babel', 'ember-metal', 'ember/features', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _emberMetal, _features, _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 ']);
if (_features.EMBER_IMPROVED_INSTRUMENTATION) {
(0, _testCase.moduleFor)('Helpers test: closure {{action}} improved instrumentation', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype.subscribe = function subscribe(eventName, options) {
this.subscriber = (0, _emberMetal.instrumentationSubscribe)(eventName, options);
};
_class.prototype.teardown = function teardown() {
if (this.subscriber) {
(0, _emberMetal.instrumentationUnsubscribe)(this.subscriber);
}
_RenderingTest.prototype.teardown.call(this);
};
_class.prototype['@test interaction event subscriber should be passed parameters'] = function testInteractionEventSubscriberShouldBePassedParameters() {
var _this2 = this;
var actionParam = 'So krispy';
var beforeParameters = [];
var afterParameters = [];
var InnerComponent = _helpers.Component.extend({
actions: {
fireAction: function () {
this.attrs.submit(actionParam);
}
}
});
var OuterComponent = _helpers.Component.extend({
outerSubmit: function () {}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: '
What it do '
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.subscribe('interaction.ember-action', {
before: function (name, timestamp, payload) {
beforeParameters.push(payload.args);
},
after: function (name, timestamp, payload) {
afterParameters.push(payload.args);
}
});
this.render('{{outer-component}}');
this.runTask(function () {
_this2.$('#instrument-button').trigger('click');
});
this.assert.deepEqual(beforeParameters, [[], [actionParam]], 'instrumentation subscriber before function was passed closure action parameters');
this.assert.deepEqual(afterParameters, [[actionParam], []], 'instrumentation subscriber after function was passed closure action parameters');
};
_class.prototype['@test interaction event subscriber should be passed target'] = function testInteractionEventSubscriberShouldBePassedTarget() {
var _this3 = this;
var beforeParameters = [];
var afterParameters = [];
var InnerComponent = _helpers.Component.extend({
myProperty: 'inner-thing',
actions: {
fireAction: function () {
this.attrs.submit();
}
}
});
var OuterComponent = _helpers.Component.extend({
myProperty: 'outer-thing',
outerSubmit: function () {}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: '
What it do '
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.subscribe('interaction.ember-action', {
before: function (name, timestamp, payload) {
beforeParameters.push(payload.target.get('myProperty'));
},
after: function (name, timestamp, payload) {
afterParameters.push(payload.target.get('myProperty'));
}
});
this.render('{{outer-component}}');
this.runTask(function () {
_this3.$('#instrument-button').trigger('click');
});
this.assert.deepEqual(beforeParameters, ['inner-thing', 'outer-thing'], 'instrumentation subscriber before function was passed target');
this.assert.deepEqual(afterParameters, ['outer-thing', 'inner-thing'], 'instrumentation subscriber after function was passed target');
};
_class.prototype['@test instrumented action should return value'] = function testInstrumentedActionShouldReturnValue() {
var _this4 = this;
var returnedValue = 'Chris P is so krispy';
var actualReturnedValue = void 0;
var InnerComponent = _helpers.Component.extend({
actions: {
fireAction: function () {
actualReturnedValue = this.attrs.submit();
}
}
});
var OuterComponent = _helpers.Component.extend({
outerSubmit: function () {
return returnedValue;
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: '
What it do '
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.subscribe('interaction.ember-action', {
before: function (name, timestamp, payload) {},
after: function (name, timestamp, payload) {}
});
this.render('{{outer-component}}');
this.runTask(function () {
_this4.$('#instrument-button').trigger('click');
});
this.assert.equal(actualReturnedValue, returnedValue, 'action can return to caller');
};
return _class;
}(_testCase.RenderingTest));
}
(0, _testCase.moduleFor)('Helpers test: closure {{action}}', function (_RenderingTest2) {
(0, _emberBabel.inherits)(_class2, _RenderingTest2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
_class2.prototype['@test action should be called'] = function testActionShouldBeCalled() {
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 testAnErrorIsTriggeredWhenBoundActionFunctionIsUndefined() {
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 testAnErrorIsTriggeredWhenBoundActionBeingPassedInIsANonFunction() {
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 test12718ANiceErrorIsShownWhenABoundActionFunctionIsUndefinedAndItIsPassedAsAttrsFoo() {
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 testActionValueIsReturned() {
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 testActionShouldBeCalledOnTheCorrectScope() {
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 testArgumentsToActionArePassedCurry() {
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 (actualFirst, actualSecond, actualThird, actualFourth) {
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 testThisCanBePassedAsAnArgument() {
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 testArgumentsToActionAreBound() {
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 testArrayArgumentsArePassedCorrectlyToAction() {
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 testMutValuesCanBeWrappedInActionsAreSettable() {
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 testMutValuesCanBeWrappedInActionsAreSettableWithACurry() {
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 testActionCanCreateClosuresOverActions() {
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 testProvidesAHelpfulErrorIfAnActionIsNotPresent() {
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 testProvidesAHelpfulErrorIfActionsHashIsNotPresent() {
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 testActionCanCreateClosuresOverActionsWithTarget() {
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 testValueCanBeUsedWithActionOverActions() {
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 testActionWillReadTheValueOfAFirstProperty() {
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 testActionWillReadTheValueOfACurriedFirstArgumentProperty() {
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 testActionClosureDoesNotGetAutoMutWrapped(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 testActionShouldBeCalledWithinARunLoop() {
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 testObjectsThatDefineINVOKECanBeCastedToActions() {
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 () {
for (var _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 testClosureActionWithMutUndefinedThingWorksProperlyGH13959() {
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 testClosureActionsDoesNotCauseComponentHooksToFireUnnecessarilyGH14305GH14654(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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/closure-action-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/closure-action-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test it concats static arguments'] = function testItConcatsStaticArguments() {
this.render('{{concat "foo" " " "bar" " " "baz"}}');
this.assertText('foo bar baz');
};
_class.prototype['@test it updates for bound arguments'] = function testItUpdatesForBoundArguments() {
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 testItCanBeUsedAsASubExpression() {
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 testItCanBeUsedAsInputForOtherHelpers() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/concat-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/concat-test.js should pass ESLint\n\n');
});
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;
(0, _testCase.moduleFor)('Helpers test: custom helpers', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test it cannot override built-in syntax'] = function testItCannotOverrideBuiltInSyntax() {
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 testItCanResolveCustomSimpleHelpersWithOrWithoutDashes() {
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 testItDoesNotResolveHelpersWithAPeriod() {
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 testItCanResolveCustomClassBasedHelpersWithOrWithoutDashes() {
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 testThrowsIfThis_superIsNotCalledFromInit() {
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 testClassBasedHelperCanRecomputeANewValue() {
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 testClassBasedHelperWithStaticArgumentsCanRecomputeANewValue() {
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 testHelperParamsCanBeReturned() {
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 testHelperHashCanBeReturned() {
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 testSimpleHelperIsCalledForParamChanges() {
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 testClassBasedHelperComputeIsCalledForParamChanges() {
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 testSimpleHelperReceivesParamsHash() {
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 testClassBasedHelperReceivesParamsHash() {
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 testClassBasedHelperUsableInSubexpressions() {
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 testParameterlessHelperIsUsableInSubexpressions() {
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 testParameterlessHelperIsUsableInAttributes() {
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 testSimpleHelperNotUsableWithABlock() {
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 testClassBasedHelperNotUsableWithABlock() {
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 testSimpleHelperNotUsableWithinElement() {
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 testClassBasedHelperNotUsableWithinElement() {
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 testClassBasedHelperIsTornDown() {
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 testClassBasedHelperUsedInSubexpressionCanRecompute() {
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 testClassBasedHelperUsedInSubexpressionCanRecomputeComponent() {
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 testClassBasedHelperUsedInSubexpressionIsDestroyed() {
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)) {
var HelperMutatingArgsTests = function (_RenderingTest2) {
(0, _emberBabel.inherits)(HelperMutatingArgsTests, _RenderingTest2);
function HelperMutatingArgsTests() {
(0, _emberBabel.classCallCheck)(this, HelperMutatingArgsTests);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
HelperMutatingArgsTests.prototype.buildCompute = function buildCompute() {
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 testCannotMutateParamsNoPositionalSpecifiedNamedSpecified() {
this.render('{{test-helper foo=bar}}', { bar: 'derp' });
};
HelperMutatingArgsTests.prototype['@test cannot mutate params - positional specified / no named specified'] = function testCannotMutateParamsPositionalSpecifiedNoNamedSpecified() {
this.render('{{test-helper bar}}', { bar: 'derp' });
};
HelperMutatingArgsTests.prototype['@test cannot mutate params - positional specified / named specified'] = function testCannotMutateParamsPositionalSpecifiedNamedSpecified() {
this.render('{{test-helper bar foo=qux}}', { bar: 'derp', qux: 'baz' });
};
HelperMutatingArgsTests.prototype['@test cannot mutate params - no positional specified / no named specified'] = function testCannotMutateParamsNoPositionalSpecifiedNoNamedSpecified() {
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() {
(0, _emberBabel.classCallCheck)(this, _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() {
(0, _emberBabel.classCallCheck)(this, _class3);
var _this25 = (0, _emberBabel.possibleConstructorReturn)(this, _HelperMutatingArgsTe2.call(this));
var compute = _this25.buildCompute();
_this25.registerHelper('test-helper', compute);
return _this25;
}
return _class3;
}(HelperMutatingArgsTests));
}
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/custom-helper-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/custom-helper-test.js should pass ESLint\n\n');
});
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/features', 'ember-runtime', 'ember-views'], function (_emberBabel, _testCase, _abstractTestCase, _helpers, _emberMetal, _features, _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;
var actionAttrs = [];
for (var i = 0; i < attributes.length; i++) {
var attr = attributes.item(i);
if (attr.name.indexOf('data-ember-action-') === 0) {
actionAttrs.push(attr.name);
}
}
return actionAttrs;
}
function getActionIds(element) {
return getActionAttributes(element).map(function (attribute) {
return attribute.slice('data-ember-action-'.length);
});
}
if (_features.EMBER_IMPROVED_INSTRUMENTATION) {
(0, _testCase.moduleFor)('Helpers test: element action instrumentation', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype.teardown = function teardown() {
_RenderingTest.prototype.teardown.call(this);
(0, _emberMetal.instrumentationReset)();
};
_class.prototype['@test action should fire interaction event with proper params'] = function testActionShouldFireInteractionEventWithProperParams() {
var _this2 = this;
var subscriberCallCount = 0;
var subscriberPayload = null;
var ExampleComponent = _helpers.Component.extend({
actions: {
foo: function () {}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Click me '
});
(0, _emberMetal.instrumentationSubscribe)('interaction.ember-action', {
before: function () {
subscriberCallCount++;
},
after: function (name, time, payload) {
subscriberPayload = payload;
}
});
this.render('{{example-component}}');
this.assert.equal(subscriberCallCount, 0, 'subscriber has not been called');
this.runTask(function () {
return _this2.rerender();
});
this.assert.equal(subscriberCallCount, 0, 'subscriber has not been called');
this.runTask(function () {
_this2.$('button').click();
});
this.assert.equal(subscriberCallCount, 1, 'subscriber has been called 1 time');
this.assert.equal(subscriberPayload.name, 'foo', 'subscriber called with correct name');
this.assert.equal(subscriberPayload.args[0], 'bar', 'subscriber called with correct args');
};
return _class;
}(_testCase.RenderingTest));
}
(0, _testCase.moduleFor)('Helpers test: element action', function (_RenderingTest2) {
(0, _emberBabel.inherits)(_class2, _RenderingTest2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
_class2.prototype['@test it can call an action on its enclosing component'] = function testItCanCallAnActionOnItsEnclosingComponent() {
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 testItCanCallAnActionWithParameters() {
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 testItShouldOutputAMarkerAttributeWithAGuid() {
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 testItShouldAllowAlternativeEventsToBeHandled() {
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 testInsideAYieldTheTargetPointsAtTheOriginalTarget() {
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 testItShouldAllowATargetToBeSpecified() {
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 testItShouldLazilyEvaluateTheTarget() {
var _this9 = this;
var firstEdit = 0;
var secondEdit = 0;
var component = void 0;
var first = {
edit: function () {
firstEdit++;
}
};
var second = {
edit: function () {
secondEdit++;
}
};
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
theTarget: first
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Edit '
});
this.render('{{example-component}}');
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 testItShouldRegisterAnEventHandler() {
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 testItHandlesWhitelistedBoundModifierKeys() {
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 testItHandlesWhitelistedBoundModifierKeysWithCurrentValue() {
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 testShouldBeAbleToUseActionMoreThanOnceForTheSameEventWithinAView() {
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 testTheEventShouldNotBubbleIfBubblesFalseIsPassed() {
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 testTheEventShouldNotBubbleIfBubblesFalseIsPassedBound() {
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 testTheBubblingDependsOnTheBoundParameter() {
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 testItShouldWorkProperlyInAnEachBlock() {
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 testItShouldWorkProperlyInAWithFooAsBarBlock() {
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 testItShouldUnregisterEventHandlersWhenAnElementActionIsRemoved() {
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 testItShouldCaptureEventsFromChildElementsAndAllowThemToTriggerTheAction() {
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 testItShouldAllowBubblingOfEventsFromActionHelperToOriginalParentEvent() {
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 testItShouldNotBubbleAnEventFromActionHelperToOriginalParentEventIfBubblesFalseIsPassed() {
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 testItShouldAllowSendAsTheActionName594() {
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 testItShouldSendTheViewEventAndCurrentContextToTheAction() {
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 testItShouldOnlyTriggerActionsForTheEventTheyWereRegisteredOn() {
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 testItShouldAllowMultipleContextsToBeSpecified() {
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 () {
for (var _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 testItShouldAllowMultipleContextsToBeSpecifiedMixedWithStringArgs() {
var _this27 = this;
var passedContexts = void 0;
var model = _emberRuntime.Object.create();
var ExampleComponent = _helpers.Component.extend({
model: model,
actions: {
edit: function () {
for (var _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 testItShouldNotTriggerActionWithSpecialClicks() {
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 testItCanTriggerActionsForKeyboardEvents() {
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 testAQuotelessParameterShouldAllowDynamicLookupOfTheActionName() {
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 testAQuotelessStringParameterShouldResolveActionNameIncludingPath() {
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 testAQuotelessFunctionParameterShouldBeCalledIncludingArguments() {
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 testAQuotelessParameterThatDoesNotResolveToAValueAsserts() {
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 testAllowsMultipleActionsOnASingleElement() {
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 testItShouldRespectPreventDefaultOptionIfProvided() {
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 testItShouldRespectPreventDefaultOptionIfProvidedBound() {
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 testItShouldTargetTheProperComponentWhenActionIsInYieldedBlockGH12409() {
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 testElementActionWithMutUndefinedThingWorksProperly() {
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 testItSupportsNonRegisteredActionsGH14888() {
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 testActionHandlerThatShiftsElementAttributesDoesnTTriggerMultipleInvocations() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/element-action-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/element-action-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _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 testShouldBeAbleToGetAnObjectValueWithAStaticKey() {
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 testShouldBeAbleToGetAnObjectValueWithNestedStaticKey() {
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 numeric keys'] = function testShouldBeAbleToGetAnObjectValueWithNumericKeys() {
var _this4 = this;
this.render('{{#each indexes as |index|}}[{{get items index}}]{{/each}}', {
indexes: [1, 2, 3],
items: {
1: 'First',
2: 'Second',
3: 'Third'
}
});
this.assertText('[First][Second][Third]');
this.runTask(function () {
return _this4.rerender();
});
this.assertText('[First][Second][Third]');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'items.1', 'Qux');
});
this.assertText('[Qux][Second][Third]');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'items', { 1: 'First', 2: 'Second', 3: 'Third' });
});
this.assertText('[First][Second][Third]');
};
_class.prototype['@test should be able to get an object value with a bound/dynamic key'] = function testShouldBeAbleToGetAnObjectValueWithABoundDynamicKey() {
var _this5 = 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 _this5.rerender();
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
(0, _emberMetal.set)(_this5.context, 'colors.apple', 'green');
(0, _emberMetal.set)(_this5.context, 'colors.banana', 'purple');
});
this.assertText('[purple] [purple]');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'key', 'apple');
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'colors', { apple: 'red' });
});
this.assertText('[red] [red]');
};
_class.prototype['@test should be able to get an object value with nested dynamic key'] = function testShouldBeAbleToGetAnObjectValueWithNestedDynamicKey() {
var _this6 = 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 _this6.rerender();
});
this.assertText('[red and yellow] [red and yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'key', 'apple.mcintosh');
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.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 testShouldBeAbleToGetAnObjectValueWithSubexpressionReturningNestedKey() {
var _this7 = 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 _this7.rerender();
});
this.assertText('[red and yellow] [red and yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.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)(_this7.context, 'colors.apple.gala', 'yellow-redish');
});
this.assertText('[yellow-redish] [yellow-redish]');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.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 testShouldBeAbleToGetAnObjectValueWithAGetHelperAsTheKey() {
var _this8 = 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 _this8.rerender();
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'key', 'key2');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
(0, _emberMetal.set)(_this8.context, 'colors.apple', 'green');
(0, _emberMetal.set)(_this8.context, 'colors.banana', 'purple');
});
this.assertText('[purple] [purple]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'key', 'key1');
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.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 testShouldBeAbleToGetAnObjectValueWithAGetHelperValueAsABoundDynamicKey() {
var _this9 = 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 _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', 'banana');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors2');
});
this.assertText('[purple] [purple]');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors1');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.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 testShouldBeAbleToGetAnObjectValueWithAGetHelperAsTheValueAndAGetHelperAsTheKey() {
var _this10 = 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 _this10.rerender();
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'objectKey', 'colors2');
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'objectKey', 'colors1');
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'key', 'key2');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'objectKey', 'colors2');
});
this.assertText('[purple] [purple]');
this.runTask(function () {
(0, _emberMetal.set)(_this10.context, 'objectKey', 'colors1');
(0, _emberMetal.set)(_this10.context, 'key', 'key1');
});
this.assertText('[red] [red]');
};
_class.prototype['@test the result of a get helper can be yielded'] = function testTheResultOfAGetHelperCanBeYielded() {
var _this11 = 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 _this11.rerender();
});
this.assertText('banana');
this.runTask(function () {
(0, _emberMetal.set)(fooBarInstance, 'mcintosh', 'yellow');
(0, _emberMetal.set)(_this11.context, 'colors', { yellow: 'bus' });
});
this.assertText('bus');
this.runTask(function () {
(0, _emberMetal.set)(fooBarInstance, 'mcintosh', 'red');
(0, _emberMetal.set)(_this11.context, 'colors', { red: 'banana' });
});
this.assertText('banana');
};
_class.prototype['@test should handle object values as nulls'] = function testShouldHandleObjectValuesAsNulls() {
var _this12 = this;
this.render('[{{get colors \'apple\'}}] [{{if true (get colors \'apple\')}}]', {
colors: null
});
this.assertText('[] []');
this.runTask(function () {
return _this12.rerender();
});
this.assertText('[] []');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'colors', { apple: 'green', banana: 'purple' });
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'colors', null);
});
this.assertText('[] []');
};
_class.prototype['@test should handle object keys as nulls'] = function testShouldHandleObjectKeysAsNulls() {
var _this13 = this;
this.render('[{{get colors key}}] [{{if true (get colors key)}}]', {
colors: {
apple: 'red',
banana: 'yellow'
},
key: null
});
this.assertText('[] []');
this.runTask(function () {
return _this13.rerender();
});
this.assertText('[] []');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'key', null);
});
this.assertText('[] []');
};
_class.prototype['@test should handle object values and keys as nulls'] = function testShouldHandleObjectValuesAndKeysAsNulls() {
this.render('[{{get colors \'apple\'}}] [{{if true (get colors key)}}]', {
colors: null,
key: null
});
this.assertText('[] []');
};
_class.prototype['@test get helper value should be updatable using {{input}} and (mut) - static key'] = function testGetHelperValueShouldBeUpdatableUsingInputAndMutStaticKey(assert) {
var _this14 = 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 _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, '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 testGetHelperValueShouldBeUpdatableUsingInputAndMutDynamicKey(assert) {
var _this15 = 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 _this15.rerender();
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'source.banana', 'yellow');
});
assert.strictEqual(this.$('#get-input').val(), 'yellow');
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.banana'), 'some value');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'key', 'apple');
});
assert.strictEqual(this.$('#get-input').val(), 'apple');
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'), 'some other value');
this.runTask(function () {
(0, _emberMetal.set)(_this15.context, 'key', 'banana');
(0, _emberMetal.set)(_this15.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 testGetHelperValueShouldBeUpdatableUsingInputAndMutDynamicNestedKey(assert) {
var _this16 = 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 _this16.rerender();
});
assert.strictEqual(this.$('#get-input').val(), 'mcintosh');
this.runTask(function () {
return (0, _emberMetal.set)(_this16.context, 'source.apple.mcintosh', 'red');
});
assert.strictEqual(this.$('#get-input').val(), 'red');
this.runTask(function () {
return _this16.$('#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)(_this16.context, 'key', 'apple.gala');
});
assert.strictEqual(this.$('#get-input').val(), 'gala');
this.runTask(function () {
return _this16.$('#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)(_this16.context, 'key', 'banana');
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
this.runTask(function () {
return _this16.$('#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)(_this16.context, 'key', 'apple.mcintosh');
(0, _emberMetal.set)(_this16.context, 'source', {
apple: {
gala: 'gala',
mcintosh: 'mcintosh'
},
banana: 'banana'
});
});
assert.strictEqual(this.$('#get-input').val(), 'mcintosh');
};
return _class;
}(_testCase.RenderingTest));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/get-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/get-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test returns a hash with the right key-value'] = function testReturnsAHashWithTheRightKeyValue() {
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 testCanHaveMoreThanOneKeyValue() {
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 testBindsValuesWhenVariablesAreUsed() {
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 testBindsMultipleValuesWhenVariablesAreUsed() {
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 testHashHelpersCanBeNested() {
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 testShouldYieldHashOfInternalProperties() {
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 testShouldYieldHashOfInternalAndExternalProperties() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/hash-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/hash-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest.apply(this, arguments));
}
_class.prototype.templateFor = function templateFor(_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 testItRaisesWhenThereAreMoreThanThreeArguments() {
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 testItRaisesWhenThereAreLessThanTwoArguments() {
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() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest2.apply(this, arguments));
}
_class2.prototype.templateFor = function templateFor(_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return '{{if (if ' + cond + ' ' + cond + ' false) ' + truthy + ' ' + falsy + '}}';
};
return _class2;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: nested {{if}} helpers (returning falsy values)', function (_IfUnlessHelperTest3) {
(0, _emberBabel.inherits)(_class3, _IfUnlessHelperTest3);
function _class3() {
(0, _emberBabel.classCallCheck)(this, _class3);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest3.apply(this, arguments));
}
_class3.prototype.templateFor = function templateFor(_ref3) {
var cond = _ref3.cond,
truthy = _ref3.truthy,
falsy = _ref3.falsy;
return '{{if (if ' + cond + ' true ' + cond + ') ' + truthy + ' ' + falsy + '}}';
};
return _class3;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: {{if}} used with another helper', function (_IfUnlessHelperTest4) {
(0, _emberBabel.inherits)(_class4, _IfUnlessHelperTest4);
function _class4() {
(0, _emberBabel.classCallCheck)(this, _class4);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest4.apply(this, arguments));
}
_class4.prototype.wrapperFor = function wrapperFor(templates) {
return '{{concat ' + templates.join(' ') + '}}';
};
_class4.prototype.templateFor = function templateFor(_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() {
(0, _emberBabel.classCallCheck)(this, _class5);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest5.apply(this, arguments));
}
_class5.prototype.wrapperFor = function wrapperFor(templates) {
return '
';
};
_class5.prototype.templateFor = function templateFor(_ref5) {
var cond = _ref5.cond,
truthy = _ref5.truthy,
falsy = _ref5.falsy;
return '{{if ' + cond + ' ' + truthy + ' ' + falsy + '}}';
};
_class5.prototype.textValue = function textValue() {
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() {
(0, _emberBabel.classCallCheck)(this, _class6);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest6.apply(this, arguments));
}
_class6.prototype.templateFor = function templateFor(_ref6) {
var cond = _ref6.cond,
truthy = _ref6.truthy,
falsy = _ref6.falsy;
return '{{if ' + cond + ' ' + truthy + '}}{{unless ' + cond + ' ' + falsy + '}}';
};
return _class6;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: inline {{unless}}', function (_IfUnlessHelperTest7) {
(0, _emberBabel.inherits)(_class7, _IfUnlessHelperTest7);
function _class7() {
(0, _emberBabel.classCallCheck)(this, _class7);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest7.apply(this, arguments));
}
_class7.prototype.templateFor = function templateFor(_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 testItRaisesWhenThereAreMoreThanThreeArguments() {
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 testItRaisesWhenThereAreLessThanTwoArguments() {
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() {
(0, _emberBabel.classCallCheck)(this, _class8);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest8.apply(this, arguments));
}
_class8.prototype.templateFor = function templateFor(_ref8) {
var cond = _ref8.cond,
truthy = _ref8.truthy,
falsy = _ref8.falsy;
return '{{unless (unless ' + cond + ' false ' + cond + ') ' + falsy + ' ' + truthy + '}}';
};
return _class8;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: nested {{unless}} helpers (returning falsy values)', function (_IfUnlessHelperTest9) {
(0, _emberBabel.inherits)(_class9, _IfUnlessHelperTest9);
function _class9() {
(0, _emberBabel.classCallCheck)(this, _class9);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest9.apply(this, arguments));
}
_class9.prototype.templateFor = function templateFor(_ref9) {
var cond = _ref9.cond,
truthy = _ref9.truthy,
falsy = _ref9.falsy;
return '{{unless (unless ' + cond + ' ' + cond + ' true) ' + falsy + ' ' + truthy + '}}';
};
return _class9;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: {{unless}} used with another helper', function (_IfUnlessHelperTest10) {
(0, _emberBabel.inherits)(_class10, _IfUnlessHelperTest10);
function _class10() {
(0, _emberBabel.classCallCheck)(this, _class10);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest10.apply(this, arguments));
}
_class10.prototype.wrapperFor = function wrapperFor(templates) {
return '{{concat ' + templates.join(' ') + '}}';
};
_class10.prototype.templateFor = function templateFor(_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() {
(0, _emberBabel.classCallCheck)(this, _class11);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest11.apply(this, arguments));
}
_class11.prototype.wrapperFor = function wrapperFor(templates) {
return '
';
};
_class11.prototype.templateFor = function templateFor(_ref11) {
var cond = _ref11.cond,
truthy = _ref11.truthy,
falsy = _ref11.falsy;
return '{{unless ' + cond + ' ' + falsy + ' ' + truthy + '}}';
};
_class11.prototype.textValue = function textValue() {
return this.$('div').attr('data-foo');
};
return _class11;
}(_sharedConditionalTests.IfUnlessHelperTest));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/if-unless-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/if-unless-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, 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 $input() {
return this.$('input');
};
InputRenderingTest.prototype.inputID = function inputID() {
return this.$input().prop('id');
};
InputRenderingTest.prototype.assertDisabled = function assertDisabled() {
this.assert.ok(this.$('input').prop('disabled'), 'The input is disabled');
};
InputRenderingTest.prototype.assertNotDisabled = function assertNotDisabled() {
this.assert.ok(this.$('input').is(':not(:disabled)'), 'The input is not disabled');
};
InputRenderingTest.prototype.assertInputId = function assertInputId(expectedId) {
this.assert.equal(this.inputID(), expectedId, 'the input id should be `expectedId`');
};
InputRenderingTest.prototype.assertSingleInput = function assertSingleInput() {
this.assert.equal(this.$('input').length, 1, 'A single text field was inserted');
};
InputRenderingTest.prototype.assertSingleCheckbox = function assertSingleCheckbox() {
this.assert.equal(this.$('input[type=checkbox]').length, 1, 'A single checkbox is added');
};
InputRenderingTest.prototype.assertCheckboxIsChecked = function assertCheckboxIsChecked() {
this.assert.equal(this.$input().prop('checked'), true, 'the checkbox is checked');
};
InputRenderingTest.prototype.assertCheckboxIsNotChecked = function assertCheckboxIsNotChecked() {
this.assert.equal(this.$input().prop('checked'), false, 'the checkbox is not checked');
};
InputRenderingTest.prototype.assertValue = function assertValue(expected) {
this.assert.equal(this.$input().val(), expected, 'the input value should be ' + expected);
};
InputRenderingTest.prototype.assertAttr = function assertAttr(name, expected) {
this.assert.equal(this.$input().attr(name), expected, 'the input ' + name + ' attribute has the value \'' + expected + '\'');
};
InputRenderingTest.prototype.assertAllAttrs = function assertAllAttrs(names, expected) {
var _this2 = this;
names.forEach(function (name) {
return _this2.assertAttr(name, expected);
});
};
InputRenderingTest.prototype.assertSelectionRange = function assertSelectionRange(start, end) {
var input = this.$input()[0];
this.assert.equal(input.selectionStart, start, 'the cursor start position should be ' + start);
this.assert.equal(input.selectionEnd, end, 'the cursor end position should be ' + end);
};
InputRenderingTest.prototype.triggerEvent = function triggerEvent(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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest.apply(this, arguments));
}
_class.prototype['@test a single text field is inserted into the DOM'] = function testASingleTextFieldIsInsertedIntoTheDOM(assert) {
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 testDefaultType() {
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 testDynamicAttributes() {
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 minlength=minlength\n size=size\n tabindex=tabindex\n }}', {
disabled: false,
value: 'Original value',
placeholder: 'Original placeholder',
name: 'original-name',
maxlength: 10,
minlength: 5,
size: 20,
tabindex: 30
});
this.assertNotDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
this.assertAttr('minlength', '5');
// this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
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('minlength', '5');
// 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);
(0, _emberMetal.set)(_this6.context, 'minlength', 6);
// set(this.context, 'size', 21); //NOTE: failing in IE (TEST_SUITE=sauce)
// set(this.context, 'tabindex', 31); //NOTE: failing in IE (TEST_SUITE=sauce)
});
this.assertDisabled();
this.assertValue('Updated value');
this.assertAttr('placeholder', 'Updated placeholder');
this.assertAttr('name', 'updated-name');
this.assertAttr('maxlength', '11');
this.assertAttr('minlength', '6');
// this.assertAttr('size', '21'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '31'); //NOTE: failing in IE (TEST_SUITE=sauce)
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);
(0, _emberMetal.set)(_this6.context, 'minlength', 5);
// set(this.context, 'size', 20); //NOTE: failing in IE (TEST_SUITE=sauce)
// set(this.context, 'tabindex', 30); //NOTE: failing in IE (TEST_SUITE=sauce)
});
this.assertNotDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
this.assertAttr('minlength', '5');
// this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
};
_class.prototype['@test static attributes'] = function testStaticAttributes() {
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 minlength=5\n size=20\n tabindex=30\n }}');
this.assertDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
this.assertAttr('minlength', '5');
// this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
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('minlength', '5');
// 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 testCursorSelectionRange(assert) {
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 testSpecifyingOnSomeeventActionFooResultsInADeprecationWarning() {
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 testSendsAnActionWithInputActionFooWhenEnterIsPressedDEPRECATED(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 testSendsAnActionWithInputEnterFooWhenEnterIsPressed(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 testSendsAnActionWithInputKeyPressFooIsPressed(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 testSendsAnActionToTheParentLevelWhenBubblesTrueIsProvided(assert) {
assert.expect(1);
var ParentComponent = _helpers.Component.extend({
change: function () {
assert.ok(true, 'bubbled upwards');
}
});
this.registerComponent('x-parent', {
ComponentClass: ParentComponent,
template: '{{input bubbles=true}}'
});
this.render('{{x-parent}}');
this.triggerEvent('change');
};
_class.prototype['@test triggers `focus-in` when focused'] = function testTriggersFocusInWhenFocused(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 testSendsInsertNewlineWhenEnterIsPressed(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 testSendsAnActionWithInputEscapePressFooWhenEscapeIsPressed(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 testSendsAnActionWithInputKeyDownFooWhenAKeyIsPressed(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 testSendsAnActionWithInputKeyUpFooWhenAKeyIsPressed(assert) {
assert.expect(1);
this.render('{{input key-up=\'foo\'}}', {
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
this.triggerEvent('keyup', {
keyCode: 65
});
};
_class.prototype['@test GH#14727 can render a file input after having had render an input of other type'] = function testGH14727CanRenderAFileInputAfterHavingHadRenderAnInputOfOtherType() {
this.render('{{input type="text"}}{{input type="file"}}');
this.assert.equal(this.$input()[0].type, 'text');
this.assert.equal(this.$input()[1].type, 'file');
};
return _class;
}(InputRenderingTest));
(0, _testCase.moduleFor)('Helpers test: {{input}} with dynamic type', function (_InputRenderingTest2) {
(0, _emberBabel.inherits)(_class2, _InputRenderingTest2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest2.apply(this, arguments));
}
_class2.prototype['@test a bound property can be used to determine type'] = function testABoundPropertyCanBeUsedToDetermineType() {
var _this13 = this;
this.render('{{input type=type}}', { type: 'password' });
this.assertAttr('type', 'password');
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 testASubexpressionCanBeUsedToDetermineType() {
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() {
(0, _emberBabel.classCallCheck)(this, _class3);
return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest3.apply(this, arguments));
}
_class3.prototype['@test dynamic attributes'] = function testDynamicAttributes() {
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 testValuePropertyAssertion() {
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 testWithABoundType(assert) {
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 testNativeClickChangesCheckProperty(assert) {
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 testWithStaticValues(assert) {
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() {
(0, _emberBabel.classCallCheck)(this, _class4);
return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest4.apply(this, arguments));
}
_class4.prototype['@test null values'] = function testNullValues(assert) {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/input-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/input-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _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 teardown() {
_RenderingTest.prototype.teardown.call(this);
_ember.default.STRINGS = this.oldString;
};
_class.prototype['@test it lets the original value through by default'] = function testItLetsTheOriginalValueThroughByDefault() {
var _this2 = this;
this.render('{{loc "Hiya buddy!"}}');
this.assertText('Hiya buddy!', 'the unlocalized string is correct');
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 testItLocalizesASimpleString() {
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 testItTakesPassedFormatsIntoAnAccount() {
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 testItUpdatesWhenBoundParamsChange() {
var _this5 = this;
this.render('{{loc simple}} - {{loc personal \'Mr. Pitkin\'}}', {
simple: 'Hello Friend',
personal: 'Hello'
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct');
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 testItUpdatesWhenNestedBoundParamsChange() {
var _this6 = this;
this.render('{{loc greetings.simple}} - {{loc greetings.personal \'Mr. Pitkin\'}}', {
greetings: {
simple: 'Hello Friend',
personal: 'Hello'
}
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct');
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/loc-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/loc-test.js should pass ESLint\n\n');
});
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(assert) {
(0, _emberBabel.classCallCheck)(this, _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 teardown() {
_RenderingTest.prototype.teardown.call(this);
_emberConsole.default.log = this.originalLog;
};
_class.prototype.assertLog = function assertLog(values) {
this.assertText('');
this.assert.strictEqual(this.logCalls.length, values.length);
for (var i = 0, len = values.length; i < len; i++) {
this.assert.strictEqual(this.logCalls[i], values[i]);
}
};
_class.prototype['@test correctly logs primitives'] = function testCorrectlyLogsPrimitives() {
this.render('{{log "one" 1 true}}');
this.assertLog(['one', 1, true]);
};
_class.prototype['@test correctly logs a property'] = function testCorrectlyLogsAProperty() {
this.render('{{log value}}', {
value: 'one'
});
this.assertLog(['one']);
};
_class.prototype['@test correctly logs multiple arguments'] = function testCorrectlyLogsMultipleArguments() {
this.render('{{log "my variable:" value}}', {
value: 'one'
});
this.assertLog(['my variable:', 'one']);
};
_class.prototype['@test correctly logs `this`'] = function testCorrectlyLogsThis() {
this.render('{{log this}}');
this.assertLog([this.context]);
};
return _class;
}(_testCase.RenderingTest));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/log-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/log-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test a simple mutable binding using `mut` propagates properly'] = function testASimpleMutableBindingUsingMutPropagatesProperly() {
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 testASimpleMutableBindingUsingMutInsertsIntoTheDOM() {
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 testPassingALiteralResultsInAAssertion() {
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 testPassingTheResultOfAHelperInvocationResultsInAnAssertion() {
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 testUsingAStringValueThroughMiddleTierDoesNotTriggerAssertionDueToTheAutoMutTransform() {
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 testReadonlyOfAMutIsConvertedIntoAnImmutableBinding() {
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 testMutableBindingsWorkInsideOfYieldedContent() {
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 testASimpleMutableBindingUsingMutIsAvailableInHooks() {
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 testAMutableBindingWithABackingComputedPropertyAndAttributePresentInTheRootOfTheComponentIsUpdatedWhenTheUpstreamPropertyInvalidates11023() {
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 testAutomaticMutableBindingsExposesAMutCellInAttrs() {
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 testAutomaticMutableBindingsTolerateUndefinedNonStreamInputsAndAttemptsToSetThem() {
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 testAutomaticMutableBindingsTolerateConstantNonStreamInputsAndAttemptsToSetThem() {
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() {
(0, _emberBabel.classCallCheck)(this, _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 testAnAttributeBindingOfAComputedPropertyOfA2WayBoundAttrRecomputesWhenTheAttrChanges() {
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 testAnAttributeBindingOfAComputedPropertyWithASetterOfA2WayBoundAttrRecomputesWhenTheAttrChanges() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/mut-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/mut-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test should render other templates registered with the container'] = function testShouldRenderOtherTemplatesRegisteredWithTheContainer() {
this.registerPartial('_subTemplateFromContainer', 'sub-template');
this.render('This {{partial "subTemplateFromContainer"}} is pretty great.');
this.assertStableRerender();
this.assertText('This sub-template is pretty great.');
};
_class.prototype['@test should render other slash-separated templates registered with the container'] = function testShouldRenderOtherSlashSeparatedTemplatesRegisteredWithTheContainer() {
this.registerPartial('child/_subTemplateFromContainer', 'sub-template');
this.render('This {{partial "child/subTemplateFromContainer"}} is pretty great.');
this.assertStableRerender();
this.assertText('This sub-template is pretty great.');
};
_class.prototype['@test should use the current context'] = function testShouldUseTheCurrentContext() {
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 testQuotelessParametersPassedToPartialPerformABoundPropertyLookupOfThePartialName() {
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 testDynamicPartialsInEach() {
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 testDynamicPartialsInWith() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/partial-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/partial-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test {{readonly}} of a path should work'] = function testReadonlyOfAPathShouldWork() {
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 testReadonlyOfAStringRendersCorrectly() {
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 testMutOfAReadonlyMutatesOnlyTheMiddleAndBottomTiers() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/readonly-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/readonly-test.js should pass ESLint\n\n');
});
enifed('ember-glimmer/tests/integration/helpers/render-test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/test-case', 'ember/features'], function (_emberBabel, _emberMetal, _emberRuntime, _testCase, _features) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{render}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test should render given template'] = function testShouldRenderGivenTemplate() {
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 testUsesControllerBasicAsTheBasisForAGeneratedControllerWhenNoneExistsForSpecifiedName() {
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 testGeneratesAControllerIfNoneExists() {
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 testShouldUseControllerWithTheSameNameAsTemplateIfPresent() {
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 testShouldRenderNestedHelpers() {
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 testShouldHaveAssertionIfTheTemplateDoesNotExist() {
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 testShouldRenderGivenTemplateWithTheSingletonControllerAsItsContext() {
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 testShouldNotDestroyTheSingletonControllerOnTeardown(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 testShouldRenderGivenTemplateWithASuppliedModel() {
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 testShouldDestroyTheNonSingletonControllersOnTeardown(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 testWithASuppliedModelShouldNotFireObserversOnTheController() {
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 testShouldRaiseAnErrorWhenAGivenControllerNameDoesNotResolveToAController() {
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 testShouldRenderWithGivenController(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 testShouldRenderTemplatesWithModelsMultipleTimes(assert) {
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 testShouldNotTreatInvocationsWithFalsyContextsAsContextLess(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 testShouldRenderTemplatesBothWithAndWithoutModels(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 testWorksWithDotNotation() {
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 testThrowsAnAssertionIfCalledWithAnUnquotedTemplateName() {
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 testThrowsAnAssertionIfCalledWithALiteralForAModel() {
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 testShouldSetRouterAsTargetWhenActionNotFoundOnParentControllerIsNotFound(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;
}
}));
var routerStub = {
send: function (actionName) {
assert.equal(actionName, 'someAction');
assert.ok(true, 'routerStub#send called');
}
};
this.owner.register('router:main', routerStub, { 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 testRenderHelperEmitsUsefulBacktrackingReRenderAssertionMessage(assert) {
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}}');
if (_features.EMBER_GLIMMER_ALLOW_BACKTRACKING_RERENDER) {
expectDeprecation(expectedBacktrackingMessage);
_this22.render('{{render \'outer\' person}}', { person: person });
} else {
expectAssertion(function () {
_this22.render('{{render \'outer\' person}}', { person: person });
}, expectedBacktrackingMessage);
}
});
};
return _class;
}(_testCase.RenderingTest));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/render-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/render-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, TextAreaRenderingTest);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this));
_this.registerComponent('-text-area', { ComponentClass: _helpers.TextArea });
return _this;
}
TextAreaRenderingTest.prototype.assertTextArea = function assertTextArea() {
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 triggerEvent(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) {
(0, _emberBabel.classCallCheck)(this, BoundTextAreaAttributes);
this.cases = cases;
}
BoundTextAreaAttributes.prototype.generate = function generate(_ref2) {
var _ref3;
var attribute = _ref2.attribute,
first = _ref2.first,
second = _ref2.second;
return _ref3 = {}, _ref3['@test ' + attribute] = function (assert) {
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _TextAreaRenderingTes.apply(this, arguments));
}
_class.prototype['@test Should insert a textarea'] = function testShouldInsertATextarea() {
this.render('{{textarea}}');
equal(this.$('textarea').length, 1);
this.assertStableRerender();
};
_class.prototype['@test Should respect disabled'] = function testShouldRespectDisabled() {
this.render('{{textarea disabled=disabled}}', {
disabled: true
});
ok(this.$('textarea').is(':disabled'));
};
_class.prototype['@test Should respect disabled when false'] = function testShouldRespectDisabledWhenFalse() {
this.render('{{textarea disabled=disabled}}', {
disabled: false
});
ok(this.$('textarea').is(':not(:disabled)'));
};
_class.prototype['@test Should become disabled when the context changes'] = function testShouldBecomeDisabledWhenTheContextChanges() {
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 testShouldBindItsContentsToTheSpecifiedValue() {
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 testGH14001ShouldCorrectlyHandleAnEmptyStringBoundValue() {
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 testShouldUpdateTheValueForCutInputChangeEvents() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/text-area-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/text-area-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test should be able to output a property without binding'] = function testShouldBeAbleToOutputAPropertyWithoutBinding() {
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 testShouldBeAbleToUseUnboundHelperInEachHelper() {
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 testShouldBeAbleToUseUnboundHelperInEachHelperWithObjects() {
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 testItShouldAssertUnboundCannotBeCalledWithMultipleArguments() {
var _this5 = this;
var willThrow = function () {
_this5.render('{{unbound foo bar}}', {
foo: 'BORK',
bar: 'BLOOP'
});
};
expectAssertion(willThrow, /unbound helper cannot be called with multiple params or hash params/);
};
_class.prototype['@test should render on attributes'] = function testShouldRenderOnAttributes() {
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 testShouldPropertyEscapeUnsafeHrefs() {
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 skipHelperFormUpdatesOnParentReRender() {
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 testSexprFormDoesNotUpdateNoMatterWhat() {
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 testSexprInHelperFormDoesNotUpdateOnParentReRender() {
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 testShouldBeAbleToRenderAnUnboundHelperInvocation() {
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 testShouldBeAbleToRenderAnBoundHelperInvocationMixedWithStaticValues() {
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 testShouldBeAbleToRenderUnboundFormsOfMultiArgHelpers() {
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 testShouldBeAbleToRenderAnUnboundHelperInvocationForHelpersWithDependentKeys() {
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 testShouldBeAbleToRenderAnUnboundHelperInvocationInEachHelper() {
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 testShouldBeAbleToRenderAnUnboundHelperInvocationWithBoundHashOptions() {
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 testShouldBeAbleToRenderBoundFormOfAHelperInsideUnboundFormOfSameHelper() {
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 testYieldingUnboundDoesNotUpdate() {
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 testYieldingUnboundHashDoesNotUpdate() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/unbound-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/unbound-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test can yield to block'] = function testCanYieldToBlock() {
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 testTemplatesShouldYieldToBlockInsideANestedComponent() {
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 testTemplatesShouldYieldToBlockWhenTheYieldIsEmbeddedInAEachHelper() {
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 testTemplatesShouldYieldToBlockWhenTheYieldIsEmbeddedInAIfHelper() {
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 testSimpleCurliesInsideOfAYieldedClockShouldWorkWhenTheYieldIsNestedInsideOfAnotherView() {
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 testNestedSimpleCurliesInsideOfAYieldedBlockShouldWorkWhenTheYieldIsNestedInsideOfAnotherView() {
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 testYieldingToANonExistentBlockIsNotAnError() {
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 testYieldUsesTheOriginalContext() {
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 testOuterBlockParamDoesnTMaskInnerComponentProperty() {
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 testInnerBlockParamDoesnTMaskYieldProperty() {
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 testCanBindABlockParamToAComponentAndUseItInYield() {
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 testYieldShouldNotIntroduceAView() {
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 testYieldWithNestedComponents3220() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/helpers/yield-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/helpers/yield-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype.runAttributeTest = function runAttributeTest(attributeName, values) {
var _this2 = this;
var template = ' ';
this.render(template, { 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 runPropertyTest(propertyName, values) {
var _this3 = this;
var attributeName = propertyName;
var template = ' ';
this.render(template, { 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 runFalsyValueProperty(values) {
var _this4 = this;
var value = 'value';
var template = ' ';
this.render(template, { 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 testInputDisabledAttribute() {
var _this5 = this;
var model = { model: { value: false } };
this.render(' ', model);
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 testInputValueAttribute() {
this.runPropertyTest('value', ['foo', 'bar']);
};
_class.prototype['@test input placeholder attribute'] = function testInputPlaceholderAttribute() {
this.runAttributeTest('placeholder', ['foo', 'bar']);
};
_class.prototype['@test input name attribute'] = function testInputNameAttribute() {
this.runAttributeTest('name', ['nam', 'name']);
};
_class.prototype['@test input maxlength attribute'] = function testInputMaxlengthAttribute() {
this.runAttributeTest('maxlength', [2, 3]);
};
_class.prototype['@test input size attribute'] = function testInputSizeAttribute() {
this.runAttributeTest('size', [2, 3]);
};
_class.prototype['@test input tabindex attribute'] = function testInputTabindexAttribute() {
this.runAttributeTest('tabindex', [2, 3]);
};
_class.prototype['@test null input value'] = function testNullInputValue() {
this.runFalsyValueProperty([null, 'hello']);
};
_class.prototype['@test undefined input value'] = function testUndefinedInputValue() {
this.runFalsyValueProperty([undefined, 'hello']);
};
_class.prototype['@test undefined `toString` method as input value'] = function testUndefinedToStringMethodAsInputValue() {
this.runFalsyValueProperty([Object.create(null), 'hello']);
};
_class.prototype['@test cursor position is not lost when updating content'] = function testCursorPositionIsNotLostWhenUpdatingContent() {
var template = ' ';
this.render(template, { value: 'hola' });
this.setDOMValue('hello');
this.setSelectionRange(1, 3);
this.setComponentValue('hello');
this.assertSelectionRange(1, 3);
// Note: We should eventually get around to testing reseting, however
// browsers handle `selectionStart` and `selectionEnd` differently
// when are synthetically testing movement of the cursor.
};
_class.prototype['@test input can be updated multiple times'] = function testInputCanBeUpdatedMultipleTimes() {
var template = ' ';
this.render(template, { value: 'hola' });
this.assertValue('hola', 'Value is initialised');
this.setComponentValue('');
this.assertValue('', 'Value is set in the DOM');
this.setDOMValue('hola');
this.setComponentValue('hola');
this.assertValue('hola', 'Value is updated the first time');
this.setComponentValue('');
this.assertValue('', 'Value is updated the second time');
};
_class.prototype['@test DOM is SSOT if value is set'] = function testDOMIsSSOTIfValueIsSet() {
var template = ' ';
this.render(template, { value: 'hola' });
this.assertValue('hola', 'Value is initialised');
this.setComponentValue('hello');
this.assertValue('hello', 'Value is initialised');
this.setDOMValue('hola');
this.assertValue('hola', 'DOM is used');
this.setComponentValue('bye');
this.assertValue('bye', 'Value is used');
// Simulates setting the input to the same value as it already is which won't cause a rerender
this.setDOMValue('hola');
this.assertValue('hola', 'DOM is used');
this.setComponentValue('hola');
this.assertValue('hola', 'Value is used');
};
_class.prototype.setDOMValue = function setDOMValue(value) {
this.inputElement().value = value;
};
_class.prototype.setComponentValue = function setComponentValue(value) {
var _this6 = this;
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'value', value);
});
};
_class.prototype.setSelectionRange = function setSelectionRange(start, end) {
this.inputElement().selectionStart = start;
this.inputElement().selectionEnd = end;
};
_class.prototype.inputElement = function inputElement() {
return this.$inputElement()[0];
};
_class.prototype.$inputElement = function $inputElement() {
return this.$('input');
};
_class.prototype.assertValue = function assertValue(value, message) {
this.assertPropertyHasValue('value', value, message);
};
_class.prototype.assertAttributeHasValue = function assertAttributeHasValue(attribute, value, message) {
this.assert.equal(this.$inputElement().attr(attribute), value, attribute + ' ' + message);
};
_class.prototype.assertPropertyHasValue = function assertPropertyHasValue(property, value, message) {
this.assert.equal(this.$inputElement().prop(property), value, property + ' ' + message);
};
_class.prototype.assertSelectionRange = function assertSelectionRange(start, end) {
this.assert.equal(this.inputElement().selectionStart, start);
this.assert.equal(this.inputElement().selectionEnd, end);
};
return _class;
}(_testCase.RenderingTest));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/input-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/input-test.js should pass ESLint\n\n');
});
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', 'ember/features'], function (_emberBabel, _emberUtils, _testCase, _helpers, _emberRuntime, _emberMetal, _emberApplication, _features) {
'use strict';
if (_features.EMBER_ENGINES_MOUNT_PARAMS) {
(0, _testCase.moduleFor)('{{mount}} single param assertion', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test it asserts that only a single param is passed'] = function testItAssertsThatOnlyASingleParamIsPassed() {
var _this2 = this;
expectAssertion(function () {
_this2.render('{{mount "chat" "foo"}}');
}, /You can only pass a single positional argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}./i);
};
return _class;
}(_testCase.RenderingTest));
} else {
(0, _testCase.moduleFor)('{{mount}} single param assertion', function (_RenderingTest2) {
(0, _emberBabel.inherits)(_class2, _RenderingTest2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
_class2.prototype['@test it asserts that only a single param is passed'] = function testItAssertsThatOnlyASingleParamIsPassed() {
var _this4 = this;
expectAssertion(function () {
_this4.render('{{mount "chat" "foo"}}');
}, /You can only pass a single argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}./i);
};
return _class2;
}(_testCase.RenderingTest));
}
(0, _testCase.moduleFor)('{{mount}} assertions', function (_RenderingTest3) {
(0, _emberBabel.inherits)(_class3, _RenderingTest3);
function _class3() {
(0, _emberBabel.classCallCheck)(this, _class3);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.apply(this, arguments));
}
_class3.prototype['@test it asserts when an invalid engine name is provided'] = function testItAssertsWhenAnInvalidEngineNameIsProvided() {
var _this6 = this;
expectAssertion(function () {
_this6.render('{{mount engineName}}', { engineName: {} });
}, /Invalid engine name '\[object Object\]' specified, engine name must be either a string, null or undefined./i);
};
_class3.prototype['@test it asserts that the specified engine is registered'] = function testItAssertsThatTheSpecifiedEngineIsRegistered() {
var _this7 = this;
expectAssertion(function () {
_this7.render('{{mount "chat"}}');
}, /You used `{{mount 'chat'}}`, but the engine 'chat' can not be found./i);
};
return _class3;
}(_testCase.RenderingTest));
(0, _testCase.moduleFor)('{{mount}} test', function (_ApplicationTest) {
(0, _emberBabel.inherits)(_class4, _ApplicationTest);
function _class4() {
(0, _emberBabel.classCallCheck)(this, _class4);
var _this8 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.call(this));
var engineRegistrations = _this8.engineRegistrations = {};
_this8.add('engine:chat', _emberApplication.Engine.extend({
router: null,
init: function () {
var _this9 = this;
this._super.apply(this, arguments);
Object.keys(engineRegistrations).forEach(function (fullName) {
_this9.register(fullName, engineRegistrations[fullName]);
});
}
}));
_this8.addTemplate('index', '{{mount "chat"}}');
return _this8;
}
_class4.prototype['@test it boots an engine, instantiates its application controller, and renders its application template'] = function testItBootsAnEngineInstantiatesItsApplicationControllerAndRendersItsApplicationTemplate(assert) {
var _this10 = 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), _this10.applicationInstance, 'engine instance has the application instance as its parent');
_this10.assertComponentElement(_this10.firstChild, { content: 'Chat here, dgeb ' });
_this10.runTask(function () {
return (0, _emberMetal.set)(controller, 'username', 'chancancode');
});
_this10.assertComponentElement(_this10.firstChild, { content: 'Chat here, chancancode ' });
_this10.runTask(function () {
return (0, _emberMetal.set)(controller, 'username', 'dgeb');
});
_this10.assertComponentElement(_this10.firstChild, { content: 'Chat here, dgeb ' });
});
};
_class4.prototype['@test it emits a useful backtracking re-render assertion message'] = function testItEmitsAUsefulBacktrackingReRenderAssertionMessage(assert) {
var _this11 = 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"\)/;
if (_features.EMBER_GLIMMER_ALLOW_BACKTRACKING_RERENDER) {
expectDeprecation(expectedBacktrackingMessage);
return this.visit('/route-with-mount');
} else {
return this.visit('/').then(function () {
expectAssertion(function () {
_this11.visit('/route-with-mount');
}, expectedBacktrackingMessage);
});
}
};
_class4.prototype['@test it renders with a bound engine name'] = function testItRendersWithABoundEngineName() {
var _this12 = 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 () {
_this12.assertComponentElement(_this12.firstChild, { content: '' });
_this12.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', 'foo');
});
_this12.assertComponentElement(_this12.firstChild, { content: 'Foo Engine ' });
_this12.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', undefined);
});
_this12.assertComponentElement(_this12.firstChild, { content: '' });
_this12.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', 'foo');
});
_this12.assertComponentElement(_this12.firstChild, { content: 'Foo Engine ' });
_this12.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', 'bar');
});
_this12.assertComponentElement(_this12.firstChild, { content: 'Bar Engine ' });
_this12.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', 'foo');
});
_this12.assertComponentElement(_this12.firstChild, { content: 'Foo Engine ' });
_this12.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', null);
});
_this12.assertComponentElement(_this12.firstChild, { content: '' });
});
};
_class4.prototype['@test it declares the event dispatcher as a singleton'] = function testItDeclaresTheEventDispatcherAsASingleton() {
var _this13 = this;
this.router.map(function () {
this.route('engine-event-dispatcher-singleton');
});
var controller = void 0;
var component = void 0;
this.add('controller:engine-event-dispatcher-singleton', _emberRuntime.Controller.extend({
init: function () {
this._super.apply(this, arguments);
controller = this;
}
}));
this.addTemplate('engine-event-dispatcher-singleton', '{{mount "foo"}}');
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: {{tagless-component}} ', { moduleName: 'application' }));
this.register('component:tagless-component', _helpers.Component.extend({
tagName: "",
init: function () {
this._super.apply(this, arguments);
component = this;
}
}));
this.register('template:components/tagless-component', (0, _helpers.compile)('Tagless Component', { moduleName: 'components/tagless-component' }));
}
}));
return this.visit('/engine-event-dispatcher-singleton').then(function () {
_this13.assertComponentElement(_this13.firstChild, { content: 'Foo Engine: Tagless Component ' });
var controllerOwnerEventDispatcher = (0, _emberUtils.getOwner)(controller).lookup('event_dispatcher:main');
var taglessComponentOwnerEventDispatcher = (0, _emberUtils.getOwner)(component).lookup('event_dispatcher:main');
_this13.assert.strictEqual(controllerOwnerEventDispatcher, taglessComponentOwnerEventDispatcher);
});
};
return _class4;
}(_testCase.ApplicationTest));
if (_features.EMBER_ENGINES_MOUNT_PARAMS) {
(0, _testCase.moduleFor)('{{mount}} params tests', function (_ApplicationTest2) {
(0, _emberBabel.inherits)(_class5, _ApplicationTest2);
function _class5() {
(0, _emberBabel.classCallCheck)(this, _class5);
var _this14 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest2.call(this));
_this14.add('engine:paramEngine', _emberApplication.Engine.extend({
router: null,
init: function () {
this._super.apply(this, arguments);
this.register('template:application', (0, _helpers.compile)('Param Engine: {{model.foo}} ', { moduleName: 'application' }));
}
}));
return _this14;
}
_class5.prototype['@test it renders with static parameters'] = function testItRendersWithStaticParameters(assert) {
var _this15 = this;
this.router.map(function () {
this.route('engine-params-static');
});
this.addTemplate('engine-params-static', '{{mount "paramEngine" model=(hash foo="bar")}}');
return this.visit('/engine-params-static').then(function () {
_this15.assertComponentElement(_this15.firstChild, { content: 'Param Engine: bar ' });
});
};
_class5.prototype['@test it renders with bound parameters'] = function testItRendersWithBoundParameters(assert) {
var _this16 = this;
this.router.map(function () {
this.route('engine-params-bound');
});
var controller = void 0;
this.add('controller:engine-params-bound', _emberRuntime.Controller.extend({
boundParamValue: null,
init: function () {
this._super();
controller = this;
}
}));
this.addTemplate('engine-params-bound', '{{mount "paramEngine" model=(hash foo=boundParamValue)}}');
return this.visit('/engine-params-bound').then(function () {
_this16.assertComponentElement(_this16.firstChild, { content: 'Param Engine: ' });
_this16.runTask(function () {
return (0, _emberMetal.set)(controller, 'boundParamValue', 'bar');
});
_this16.assertComponentElement(_this16.firstChild, { content: 'Param Engine: bar ' });
_this16.runTask(function () {
return (0, _emberMetal.set)(controller, 'boundParamValue', undefined);
});
_this16.assertComponentElement(_this16.firstChild, { content: 'Param Engine: ' });
_this16.runTask(function () {
return (0, _emberMetal.set)(controller, 'boundParamValue', 'bar');
});
_this16.assertComponentElement(_this16.firstChild, { content: 'Param Engine: bar ' });
_this16.runTask(function () {
return (0, _emberMetal.set)(controller, 'boundParamValue', 'baz');
});
_this16.assertComponentElement(_this16.firstChild, { content: 'Param Engine: baz ' });
_this16.runTask(function () {
return (0, _emberMetal.set)(controller, 'boundParamValue', 'bar');
});
_this16.assertComponentElement(_this16.firstChild, { content: 'Param Engine: bar ' });
_this16.runTask(function () {
return (0, _emberMetal.set)(controller, 'boundParamValue', null);
});
_this16.assertComponentElement(_this16.firstChild, { content: 'Param Engine: ' });
});
};
_class5.prototype['@test it renders contextual components passed as parameter values'] = function testItRendersContextualComponentsPassedAsParameterValues(assert) {
var _this17 = this;
this.router.map(function () {
this.route('engine-params-contextual-component');
});
this.addComponent("foo-component", {
template: 'foo-component rendered! - {{app-bar-component}}'
});
this.addComponent('app-bar-component', {
ComponentClass: _helpers.Component.extend({ tagName: "" }),
template: 'rendered app-bar-component from the app'
});
this.add('engine:componentParamEngine', _emberApplication.Engine.extend({
router: null,
init: function () {
this._super.apply(this, arguments);
this.register('template:application', (0, _helpers.compile)('{{model.foo}}', { moduleName: 'application' }));
}
}));
this.addTemplate('engine-params-contextual-component', '{{mount "componentParamEngine" model=(hash foo=(component "foo-component"))}}');
return this.visit('/engine-params-contextual-component').then(function () {
_this17.assertComponentElement(_this17.firstChild.firstChild, { content: 'foo-component rendered! - rendered app-bar-component from the app' });
});
};
return _class5;
}(_testCase.ApplicationTest));
}
});
QUnit.module('ESLint | ember-glimmer/tests/integration/mount-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/mount-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _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 testShouldNotErrorWhenInitialRenderedTemplateIsUndefined() {
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 testShouldRenderTheOutletWhenSetAfterDOMInsertion() {
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 testShouldRenderTheOutletWhenSetBeforeDOMInsertion() {
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 testShouldSupportAnOptionalName() {
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 testDoesNotDefaultOutletNameWhenPositionalArgumentIsPresent() {
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 testShouldSupportBoundOutletName() {
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 testOutletStateCanPassThroughUserCodeLiquidFireInitimateAPI() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/outlet-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/outlet-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test block params should not be refined'] = function testBlockParamsShouldNotBeRefined() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/refinements-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/refinements-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test unquoted viewBox property is output'] = function testUnquotedViewBoxPropertyIsOutput(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 testQuotedViewBoxPropertyIsOutput(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 testQuotedViewBoxPropertyIsConcat() {
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 testClassIsOutput() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/svg-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/svg-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, EachInTest);
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingSyntaxCondit.apply(this, arguments));
}
EachInTest.prototype.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{#each-in ' + cond + ' as |key|}}' + truthy + '{{else}}' + falsy + '{{/each-in}}';
};
return EachInTest;
}(_sharedConditionalTests.TogglingSyntaxConditionalsTest);
function EmptyFunction() {}
function NonEmptyFunction() {}
NonEmptyFunction.foo = 'bar';
var EmptyConstructor = function EmptyConstructor() {
(0, _emberBabel.classCallCheck)(this, EmptyConstructor);
};
var NonEmptyConstructor = function NonEmptyConstructor() {
(0, _emberBabel.classCallCheck)(this, NonEmptyConstructor);
};
NonEmptyConstructor.foo = 'bar';
var BasicEachInTest = function (_EachInTest) {
(0, _emberBabel.inherits)(BasicEachInTest, _EachInTest);
function BasicEachInTest() {
(0, _emberBabel.classCallCheck)(this, 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, [], EmptyFunction, EmptyConstructor, {}, 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() {
(0, _emberBabel.classCallCheck)(this, _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 testKeyingOffOfUndefinedDoesNotRender(assert) {
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 testItIterateOverArrayWithInInsteadOfWalkingOverElements(assert) {
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 testItSkipsHolesInSparseArrays(assert) {
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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, _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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, _class3);
return (0, _emberBabel.possibleConstructorReturn)(this, _EachInProxyTest.apply(this, arguments));
}
_class3.prototype['@test it iterates over the content, not the proxy'] = function testItIteratesOverTheContentNotTheProxy() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/syntax/each-in-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/syntax/each-in-test.js should pass ESLint\n\n');
});
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) {
(0, _emberBabel.classCallCheck)(this, ArrayLike);
this._array = content;
}
ArrayLike.prototype.forEach = function forEach(callback) {
this._array.forEach(callback);
};
ArrayLike.prototype.objectAt = function objectAt(idx) {
return this._array[idx];
};
ArrayLike.prototype.clear = function clear() {
this._array.length = 0;
this.arrayContentDidChange();
};
ArrayLike.prototype.replace = function replace(idx, del, ins) {
var _array;
(_array = this._array).splice.apply(_array, [idx, del].concat(ins));
this.arrayContentDidChange();
};
ArrayLike.prototype.unshiftObject = function unshiftObject(obj) {
this._array.unshift(obj);
this.arrayContentDidChange();
};
ArrayLike.prototype.unshiftObjects = function unshiftObjects(arr) {
var _array2;
(_array2 = this._array).unshift.apply(_array2, arr);
this.arrayContentDidChange();
};
ArrayLike.prototype.pushObject = function pushObject(obj) {
this._array.push(obj);
this.arrayContentDidChange();
};
ArrayLike.prototype.pushObjects = function pushObjects(arr) {
var _array3;
(_array3 = this._array).push.apply(_array3, arr);
this.arrayContentDidChange();
};
ArrayLike.prototype.shiftObject = function shiftObject() {
var obj = this._array.shift();
this.arrayContentDidChange();
return obj;
};
ArrayLike.prototype.popObject = function popObject() {
var obj = this._array.pop();
this.arrayContentDidChange();
return obj;
};
ArrayLike.prototype.insertAt = function insertAt(idx, obj) {
this._array.splice(idx, 0, obj);
this.arrayContentDidChange();
};
ArrayLike.prototype.removeAt = function removeAt(idx) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
this._array.splice(idx, len);
this.arrayContentDidChange();
};
ArrayLike.prototype.arrayContentDidChange = function arrayContentDidChange() {
(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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicEachTest.apply(this, arguments));
}
_class.prototype.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{#each ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/each}}';
};
return _class;
}(BasicEachTest));
(0, _testCase.moduleFor)('Syntax test: toggling {{#each as}}', function (_BasicEachTest2) {
(0, _emberBabel.inherits)(_class2, _BasicEachTest2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicEachTest2.apply(this, arguments));
}
_class2.prototype.templateFor = function templateFor(_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return '{{#each ' + cond + ' as |test|}}' + truthy + '{{else}}' + falsy + '{{/each}}';
};
return _class2;
}(BasicEachTest));
var EachEdgeCasesTest = function (_TogglingEachTest2) {
(0, _emberBabel.inherits)(EachEdgeCasesTest, _TogglingEachTest2);
function EachEdgeCasesTest() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, _class3);
return (0, _emberBabel.possibleConstructorReturn)(this, _EachEdgeCasesTest.apply(this, arguments));
}
_class3.prototype.templateFor = function templateFor(_ref3) {
var cond = _ref3.cond,
truthy = _ref3.truthy,
falsy = _ref3.falsy;
return '{{#each ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/each}}';
};
return _class3;
}(EachEdgeCasesTest));
(0, _testCase.moduleFor)('Syntax test: toggling {{#each as}}', function (_EachEdgeCasesTest2) {
(0, _emberBabel.inherits)(_class4, _EachEdgeCasesTest2);
function _class4() {
(0, _emberBabel.classCallCheck)(this, _class4);
return (0, _emberBabel.possibleConstructorReturn)(this, _EachEdgeCasesTest2.apply(this, arguments));
}
_class4.prototype.templateFor = function templateFor(_ref4) {
var cond = _ref4.cond,
truthy = _ref4.truthy,
falsy = _ref4.falsy;
return '{{#each ' + cond + ' as |test|}}' + truthy + '{{else}}' + falsy + '{{/each}}';
};
return _class4;
}(EachEdgeCasesTest));
var AbstractEachTest = function (_RenderingTest) {
(0, _emberBabel.inherits)(AbstractEachTest, _RenderingTest);
function AbstractEachTest() {
(0, _emberBabel.classCallCheck)(this, AbstractEachTest);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
AbstractEachTest.prototype.makeList = function makeList() {
// this.list = this.delegate = ...;
throw new Error('Not implemented: `makeList`');
};
AbstractEachTest.prototype.replaceList = function replaceList(list) {
var _this9 = this;
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'list', _this9.makeList(list));
});
};
AbstractEachTest.prototype.forEach = function forEach(callback) {
return this.delegate.forEach(callback);
};
AbstractEachTest.prototype.objectAt = function objectAt(idx) {
return this.delegate.objectAt(idx);
};
AbstractEachTest.prototype.clear = function clear() {
return this.delegate.clear();
};
AbstractEachTest.prototype.replace = function replace(idx, del, ins) {
return this.delegate.replace(idx, del, ins);
};
AbstractEachTest.prototype.unshiftObject = function unshiftObject(obj) {
return this.delegate.unshiftObject(obj);
};
AbstractEachTest.prototype.unshiftObjects = function unshiftObjects(arr) {
return this.delegate.unshiftObjects(arr);
};
AbstractEachTest.prototype.pushObject = function pushObject(obj) {
return this.delegate.pushObject(obj);
};
AbstractEachTest.prototype.pushObjects = function pushObjects(arr) {
return this.delegate.pushObjects(arr);
};
AbstractEachTest.prototype.shiftObject = function shiftObject() {
return this.delegate.shiftObject();
};
AbstractEachTest.prototype.popObject = function popObject() {
return this.delegate.popObject();
};
AbstractEachTest.prototype.insertAt = function insertAt(idx, obj) {
return this.delegate.insertAt(idx, obj);
};
AbstractEachTest.prototype.removeAt = function removeAt(idx, len) {
return this.delegate.removeAt(idx, len);
};
AbstractEachTest.prototype.render = function render(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() {
(0, _emberBabel.classCallCheck)(this, 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 testItRepeatsTheGivenBlockForEachItemInTheArray() {
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 testItReceivesTheIndexAsTheSecondParameter() {
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 testItAcceptsAStringKey() {
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 testItAcceptsANumericKey() {
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 testItCanSpecifyIndexAsTheKey() {
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 testItCanSpecifyIdentityAsTheKeyForArraysOfPrimitives() {
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 testItCanSpecifyIdentityAsTheKeyForMixedArraysOfObjectsAndPrimitives() {
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 testItCanRenderDuplicatePrimitiveItems() {
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 (assert) {
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 testItCanRenderDuplicateObjects() {
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 testContextIsNotChangedToTheInnerScopeInsideAnEachAsBlock() {
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 testCanAccessTheItemAndTheOriginalScope() {
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 testTheScopedVariableIsNotAvailableOutsideTheEachBlock() {
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 testInverseTemplateIsDisplayedWithContext() {
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 testContentThatAreNotInitiallyPresentUpdatesCorrectlyGH13983() {
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() {
(0, _emberBabel.classCallCheck)(this, _class5);
return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest.apply(this, arguments));
}
_class5.prototype.makeList = function makeList(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() {
(0, _emberBabel.classCallCheck)(this, _class6);
return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest2.apply(this, arguments));
}
_class6.prototype.makeList = function makeList(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() {
(0, _emberBabel.classCallCheck)(this, _class7);
return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest3.apply(this, arguments));
}
_class7.prototype.makeList = function makeList(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() {
(0, _emberBabel.classCallCheck)(this, _class8);
return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest4.apply(this, arguments));
}
_class8.prototype.makeList = function makeList(list) {
var content = this.delegate = (0, _emberRuntime.A)(list);
return this.list = _emberRuntime.ArrayProxy.create({ content: content });
};
_class8.prototype.replaceList = function replaceList(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() {
(0, _emberBabel.classCallCheck)(this, _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 testReUsingTheSameVariableWithDifferentEachBlocksDoesNotOverrideEachOther() {
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 testTheScopedVariableIsNotAvailableOutsideTheEachBlock() {
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 testItShouldSupportEachNameAsFooThenEachFooAsBar() {
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() {
(0, _emberBabel.classCallCheck)(this, _class10);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.apply(this, arguments));
}
_class10.prototype['@test keying off of `undefined` does not render'] = function testKeyingOffOfUndefinedDoesNotRender(assert) {
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() {
(0, _emberBabel.classCallCheck)(this, _class11);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest4.apply(this, arguments));
}
_class11.prototype['@test it should itterate over holes'] = function testItShouldItterateOverHoles(assert) {
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() {
(0, _emberBabel.classCallCheck)(this, _class12);
var _this43 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest5.call(this));
_this43.observer = null;
return _this43;
}
_class12.prototype.observe = function observe(element) {
var observer = this.observer = new MutationObserver(function () {});
observer.observe(element, { childList: true, characterData: true });
};
_class12.prototype.teardown = function teardown() {
if (this.observer) {
this.observer.disconnect();
}
_RenderingTest5.prototype.teardown.call(this);
};
_class12.prototype.assertNoMutation = function assertNoMutation() {
this.assert.deepEqual(this.observer.takeRecords(), [], 'Expected no mutations');
};
_class12.prototype.expectMutations = function expectMutations() {
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 testEachShouldNotMutateASubtreeWhenTheArrayHasNotChangedGH14332(assert) {
var _this44 = this;
var page = { title: 'Blog Posts' };
var model = [{ title: 'Rails is omakase' }, { title: 'Ember is omakase' }];
this.render((0, _abstractTestCase.strip)(_templateObject5), { page: page, model: model });
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));
}
});
QUnit.module('ESLint | ember-glimmer/tests/integration/syntax/each-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/syntax/each-test.js should pass ESLint\n\n');
});
enifed('ember-glimmer/tests/integration/syntax/experimental-syntax-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer', '@glimmer/runtime'], function (_emberBabel, _testCase, _abstractTestCase, _emberGlimmer, _runtime) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#-let obj as |bar|}}\n {{bar}}\n {{/-let}}\n '], ['\n {{#-let obj as |bar|}}\n {{bar}}\n {{/-let}}\n ']);
(0, _testCase.moduleFor)('registerMacros', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var originalMacros = _emberGlimmer._experimentalMacros.slice();
(0, _emberGlimmer._registerMacros)(function (blocks, inlines) {
blocks.add('-let', function (params, hash, _default, inverse, builder) {
(0, _runtime.compileExpression)(params[0], builder);
builder.invokeStatic(_default, 1);
});
});
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this));
_this.originalMacros = originalMacros;
return _this;
}
_class.prototype.teardown = function teardown() {
_emberGlimmer._experimentalMacros.length = 0;
this.originalMacros.forEach(function (macro) {
return _emberGlimmer._experimentalMacros.push(macro);
});
_RenderingTest.prototype.teardown.call(this);
};
_class.prototype['@test allows registering custom syntax via private API'] = function testAllowsRegisteringCustomSyntaxViaPrivateAPI(assert) {
this.render((0, _abstractTestCase.strip)(_templateObject), { obj: 'hello world!' });
this.assertText('hello world!');
};
return _class;
}(_testCase.RenderingTest));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/syntax/experimental-syntax-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/syntax/experimental-syntax-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe.apply(this, arguments));
}
_class.prototype.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{#if ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/if}}';
};
return _class;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: {{#unless}} with inverse', function (_IfUnlessWithSyntaxTe2) {
(0, _emberBabel.inherits)(_class2, _IfUnlessWithSyntaxTe2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe2.apply(this, arguments));
}
_class2.prototype.templateFor = function templateFor(_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return '{{#unless ' + cond + '}}' + falsy + '{{else}}' + truthy + '{{/unless}}';
};
return _class2;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: {{#if}} and {{#unless}} without inverse', function (_IfUnlessWithSyntaxTe3) {
(0, _emberBabel.inherits)(_class3, _IfUnlessWithSyntaxTe3);
function _class3() {
(0, _emberBabel.classCallCheck)(this, _class3);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe3.apply(this, arguments));
}
_class3.prototype.templateFor = function templateFor(_ref3) {
var cond = _ref3.cond,
truthy = _ref3.truthy,
falsy = _ref3.falsy;
return '{{#if ' + cond + '}}' + truthy + '{{/if}}{{#unless ' + cond + '}}' + falsy + '{{/unless}}';
};
return _class3;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: {{#if}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class4, _RenderingTest);
function _class4() {
(0, _emberBabel.classCallCheck)(this, _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 testUsingIfWithAnEachDestroysComponentsWhenTransitioningToAndFromInverseGH12267(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 testLookingUpUndefinedPropertyDefaultsToFalse(assert) {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/syntax/if-unless-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/syntax/if-unless-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test allows rendering into an external element'] = function testAllowsRenderingIntoAnExternalElement(assert) {
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 testComponentsAreCleanedUpProperly(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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/syntax/in-element-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/syntax/in-element-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test does not allow setting values other than outletState'] = function testDoesNotAllowSettingValuesOtherThanOutletState(assert) {
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 testAllowsSettingGettingOutletState(assert) {
// 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 testDoesNotAllowSettingValuesOtherThanOutletState(assert) {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/syntax/with-dynamic-var-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/syntax/with-dynamic-var-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe.apply(this, arguments));
}
_class.prototype.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{#with ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/with}}';
};
return _class;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: {{#with as}}', function (_IfUnlessWithSyntaxTe2) {
(0, _emberBabel.inherits)(_class2, _IfUnlessWithSyntaxTe2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe2.apply(this, arguments));
}
_class2.prototype.templateFor = function templateFor(_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 testKeyingOffOfUndefinedDoesNotRender(assert) {
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 testItRendersAndHidesTheGivenBlockBasedOnTheConditional() {
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 testCanAccessAliasAndOriginalScope() {
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 testTheScopedVariableIsNotAvailableOutsideTheWithBlock() {
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 testInverseTemplateIsDisplayedWithContext() {
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 testCanAccessAliasOfAProxy() {
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 testCanAccessAliasOfAnArray() {
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 testAttrsCanBeUsedAsABlockParamGH14678() {
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() {
(0, _emberBabel.classCallCheck)(this, _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 testReUsingTheSameVariableWithDifferentWithBlocksDoesNotOverrideEachOther() {
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 testTheScopedVariableIsNotAvailableOutsideTheWithBlock() {
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 testItShouldSupportWithNameAsFooThenWithFooAsBar() {
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 testUpdatingTheContextShouldUpdateTheAlias() {
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 testNestedWithBlocksShouldHaveAccessToRootContext() {
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));
});
QUnit.module('ESLint | ember-glimmer/tests/integration/syntax/with-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/integration/syntax/with-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, Counter);
this.reset();
}
Counter.prototype.increment = function increment(key) {
this.total++;
return this.counts[key] = (this.counts[key] || 0) + 1;
};
Counter.prototype.get = function get(key) {
return this.counts[key] || 0;
};
Counter.prototype.reset = function reset() {
this.total = 0;
this.counts = Object.create(null);
};
return Counter;
}();
var COUNTER = new Counter();
var BasicCompiler = function () {
function BasicCompiler(template) {
(0, _emberBabel.classCallCheck)(this, BasicCompiler);
this.template = template;
}
BasicCompiler.prototype.compile = function compile(builder) {
var template = this.template;
COUNTER.increment(this.constructor.id + '+' + template.id);
builder.wrapLayout(template);
};
return BasicCompiler;
}();
var TypeOneCompiler = function (_BasicCompiler) {
(0, _emberBabel.inherits)(TypeOneCompiler, _BasicCompiler);
function TypeOneCompiler() {
(0, _emberBabel.classCallCheck)(this, TypeOneCompiler);
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicCompiler.apply(this, arguments));
}
return TypeOneCompiler;
}(BasicCompiler);
var TypeTwoCompiler = function (_BasicCompiler2) {
(0, _emberBabel.inherits)(TypeTwoCompiler, _BasicCompiler2);
function TypeTwoCompiler() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this3 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this));
COUNTER.reset();
return _this3;
}
_class.prototype.templateFor = function templateFor(content) {
var Factory = this.compile(content);
return this.env.getTemplate(Factory, this.owner);
};
_class.prototype['@test each template is only compiled once'] = function testEachTemplateIsOnlyCompiledOnce(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.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
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.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
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.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
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.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
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 testEachTemplateCompilerPairIsTreatedAsUnique(assert) {
var env = this.env;
var template = this.templateFor('Hello world!');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
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.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
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.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
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.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
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 testATemplateInstanceIsReturnedEnsuresTemplatesCanBeInjectedIntoLayoutProperty(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.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledDynamicTemplate, 'should return a CompiledDynamicTemplate');
};
return _class;
}(_testCase.RenderingTest));
});
QUnit.module('ESLint | ember-glimmer/tests/unit/layout-cache-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/unit/layout-cache-test.js should pass ESLint\n\n');
});
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 renderer = {
appendOutletView: function (view, target) {
didAppendOutletView++;
assert.equal(view, outletView);
assert.equal(target, expectedOutlet);
}
};
var outletView = new _outlet.default({}, renderer);
(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');
});
});
});
});
QUnit.module('ESLint | ember-glimmer/tests/unit/outlet-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/unit/outlet-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _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 testTheTemplateFactoryReturnedFromPrecompileIsTheSameAsCompile(assert) {
var env = this.env;
var templateStr = 'Hello {{name}}';
var options = { moduleName: 'some-module' };
var spec = (0, _emberTemplateCompiler.precompile)(templateStr, options);
var body = 'exports.default = template(' + spec + ');';
var module = new Function('exports', 'template', body);
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));
});
QUnit.module('ESLint | ember-glimmer/tests/unit/template-factory-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/unit/template-factory-test.js should pass ESLint\n\n');
});
enifed('ember-glimmer/tests/unit/utils/debug-stack-test', ['ember-glimmer/utils/debug-stack'], function (_debugStack) {
'use strict';
if (true) {
QUnit.module('Glimmer DebugStack');
QUnit.test('pushing and popping', function (assert) {
var stack = new _debugStack.default();
assert.equal(stack.peek(), undefined);
stack.push('template:application');
assert.equal(stack.peek(), '"template:application"');
stack.push('component:top-level-component');
assert.equal(stack.peek(), '"component:top-level-component"');
stack.pushEngine('engine:my-engine');
stack.push('component:component-in-engine');
assert.equal(stack.peek(), '"component:component-in-engine" (in "engine:my-engine")');
stack.pop();
stack.pop();
var item = stack.pop();
assert.equal(item, 'component:top-level-component');
assert.equal(stack.peek(), '"template:application"');
});
}
});
QUnit.module('ESLint | ember-glimmer/tests/unit/utils/debug-stack-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/unit/utils/debug-stack-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase.apply(this, arguments));
}
_class.prototype['@test iterates over an array'] = function testIteratesOverAnArray() {
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 testIteratesOverAnEmberA() {
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 testReturnsNullWhenOutOfItems() {
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 testIteratesOverAnArrayWithIndicesAsKeys() {
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 testIteratesOverAnArrayWithIdentitiesAsKeys() {
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 testIteratesOverAnArrayWithArbitraryPropertiesAsKeys() {
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 testErrorsOnNextWithAnUndefinedRef() {
var iterator = iteratorForArray(undefined);
this.assert.expect(1);
try {
iterator.next();
} catch (_ref) {
var 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 testErrorsOnNextWithANullRef() {
var iterator = iteratorForArray(null);
this.assert.expect(1);
try {
iterator.next();
} catch (_ref2) {
var 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 testErrorsOnNextWithAnInvalidRefType() {
var iterator = iteratorForArray('string');
this.assert.expect(1);
try {
iterator.next();
} catch (_ref3) {
var 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 testErrorsOnNextWithAnEmptyArray() {
var iterator = iteratorForArray([]);
this.assert.expect(1);
try {
iterator.next();
} catch (_ref4) {
var message = _ref4.message;
this.assert.equal(message, 'Cannot call next() on an empty iterator');
}
};
_class.prototype['@test ensures keys are unique'] = function testEnsuresKeysAreUnique() {
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();
}
});
QUnit.module('ESLint | ember-glimmer/tests/unit/utils/iterable-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/unit/utils/iterable-test.js should pass ESLint\n\n');
});
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;
}
});
});
QUnit.module('ESLint | ember-glimmer/tests/utils/abstract-test-case.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/utils/abstract-test-case.js should pass ESLint\n\n');
});
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;
}
});
});
QUnit.module('ESLint | ember-glimmer/tests/utils/helpers.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/utils/helpers.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, AbstractConditionalsTest);
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
AbstractConditionalsTest.prototype.wrapperFor = function wrapperFor(templates) {
return templates.join('');
};
AbstractConditionalsTest.prototype.wrappedTemplateFor = function wrappedTemplateFor(options) {
return this.wrapperFor([this.templateFor(options)]);
};
AbstractConditionalsTest.prototype.templateFor = function templateFor(_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 renderValues() {
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) {
(0, _emberBabel.classCallCheck)(this, AbstractGenerator);
this.cases = cases;
}
/* abstract */
AbstractGenerator.prototype.generate = function generate(value, idx) {
throw new Error('Not implemented: `generate`');
};
return AbstractGenerator;
}();
var TruthyGenerator = exports.TruthyGenerator = function (_AbstractGenerator) {
(0, _emberBabel.inherits)(TruthyGenerator, _AbstractGenerator);
function TruthyGenerator() {
(0, _emberBabel.classCallCheck)(this, TruthyGenerator);
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator.apply(this, arguments));
}
TruthyGenerator.prototype.generate = function generate(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() {
(0, _emberBabel.classCallCheck)(this, FalsyGenerator);
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator2.apply(this, arguments));
}
FalsyGenerator.prototype.generate = function generate(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() {
(0, _emberBabel.classCallCheck)(this, StableTruthyGenerator);
return (0, _emberBabel.possibleConstructorReturn)(this, _TruthyGenerator.apply(this, arguments));
}
StableTruthyGenerator.prototype.generate = function generate(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() {
(0, _emberBabel.classCallCheck)(this, StableFalsyGenerator);
return (0, _emberBabel.possibleConstructorReturn)(this, _FalsyGenerator.apply(this, arguments));
}
StableFalsyGenerator.prototype.generate = function generate(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() {
(0, _emberBabel.classCallCheck)(this, ObjectProxyGenerator);
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator3.apply(this, arguments));
}
ObjectProxyGenerator.prototype.generate = function generate(value, idx) {
// This is inconsistent with our usual to-bool policy, but the current proxy implementation
// simply uses !!content to determine truthiness
if (value) {
var _ref4;
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 {
var _ref5;
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() {
(0, _emberBabel.classCallCheck)(this, BasicConditionalsTest);
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractConditionals.apply(this, arguments));
}
BasicConditionalsTest.prototype['@test it renders the corresponding block based on the conditional'] = function testItRendersTheCorrespondingBlockBasedOnTheConditional() {
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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, TogglingHelperConditionalsTest);
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingConditionals.apply(this, arguments));
}
TogglingHelperConditionalsTest.prototype.renderValues = function renderValues() {
var templates = [];
var context = {};
for (var i = 1; i <= arguments.length; i++) {
templates.push(this.templateFor({ cond: 'cond' + i, truthy: 't' + i, falsy: 'f' + i }));
context['t' + i] = 'T' + i;
context['f' + i] = 'F' + i;
context['cond' + i] = 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 testItHasAccessToTheOuterScopeFromBothTemplates() {
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 testItDoesNotUpdateWhenTheUnboundHelperIsUsed() {
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 testEvaluationShouldBeLazy(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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, TogglingSyntaxConditionalsTest);
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingConditionals2.apply(this, arguments));
}
TogglingSyntaxConditionalsTest.prototype.renderValues = function renderValues() {
var templates = [];
var context = {};
for (var i = 1; i <= arguments.length; i++) {
templates.push(this.templateFor({ cond: 'cond' + i, truthy: '{{t}}' + i, falsy: '{{f}}' + i }));
context['cond' + i] = 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 testItDoesNotUpdateWhenTheUnboundHelperIsUsed() {
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 testItHasAccessToTheOuterScopeFromBothTemplates() {
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 testItUpdatesCorrectlyWhenEnclosingAnotherConditional() {
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 testItUpdatesCorrectlyWhenEnclosingEach() {
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 testItUpdatesCorrectlyWhenEnclosingTripleCurlies() {
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 testChildConditionalShouldNotRenderChildrenIfParentConditionalBecomesFalse(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 testEvaluationShouldBeLazy(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() {
(0, _emberBabel.classCallCheck)(this, IfUnlessWithSyntaxTest);
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingSyntaxCondit.apply(this, arguments));
}
return IfUnlessWithSyntaxTest;
}(TogglingSyntaxConditionalsTest);
_abstractTestCase.applyMixins.apply(undefined, [IfUnlessWithSyntaxTest].concat(IfUnlessWithTestCases));
});
QUnit.module('ESLint | ember-glimmer/tests/utils/shared-conditional-tests.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/utils/shared-conditional-tests.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase.apply(this, arguments));
}
_class.prototype['@test htmlSafe should return an instance of SafeString'] = function testHtmlSafeShouldReturnAnInstanceOfSafeString() {
var safeString = (0, _helpers.htmlSafe)('you need to be more bold ');
this.assert.ok(safeString instanceof _helpers.SafeString, 'should be a SafeString');
};
_class.prototype['@test htmlSafe should return an empty string for null'] = function testHtmlSafeShouldReturnAnEmptyStringForNull() {
var safeString = (0, _helpers.htmlSafe)(null);
this.assert.equal(safeString instanceof _helpers.SafeString, true, 'should be a SafeString');
this.assert.equal(safeString.toString(), '', 'should return an empty string');
};
_class.prototype['@test htmlSafe should return an instance of SafeString'] = function testHtmlSafeShouldReturnAnInstanceOfSafeString() {
var safeString = (0, _helpers.htmlSafe)();
this.assert.equal(safeString instanceof _helpers.SafeString, true, 'should be a SafeString');
this.assert.equal(safeString.toString(), '', 'should return an empty string');
};
return _class;
}(_abstractTestCase.TestCase));
(0, _testCase.moduleFor)('SafeString isHTMLSafe', function (_TestCase2) {
(0, _emberBabel.inherits)(_class2, _TestCase2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase2.apply(this, arguments));
}
_class2.prototype['@test isHTMLSafe should detect SafeString'] = function testIsHTMLSafeShouldDetectSafeString() {
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 testIsHTMLSafeShouldNotDetectSafeStringOnPrimatives() {
this.assert.notOk((0, _helpers.isHTMLSafe)('Hello World'));
this.assert.notOk((0, _helpers.isHTMLSafe)({}));
this.assert.notOk((0, _helpers.isHTMLSafe)([]));
this.assert.notOk((0, _helpers.isHTMLSafe)(10));
this.assert.notOk((0, _helpers.isHTMLSafe)(null));
};
return _class2;
}(_abstractTestCase.TestCase));
});
QUnit.module('ESLint | ember-glimmer/tests/utils/string-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/utils/string-test.js should pass ESLint\n\n');
});
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;
}
});
});
QUnit.module('ESLint | ember-glimmer/tests/utils/test-case.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/utils/test-case.js should pass ESLint\n\n');
});
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;
}
});
});
QUnit.module('ESLint | ember-glimmer/tests/utils/test-helpers.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/tests/utils/test-helpers.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/utils/bindings.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/utils/bindings.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/utils/curly-component-state-bucket.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/utils/curly-component-state-bucket.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/utils/debug-stack.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/utils/debug-stack.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/utils/iterable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/utils/iterable.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/utils/process-args.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/utils/process-args.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/utils/references.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/utils/references.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/utils/string.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/utils/string.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/utils/to-bool.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/utils/to-bool.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-glimmer/views/outlet.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-glimmer/views/outlet.js should pass ESLint\n\n');
});
enifed('ember-metal/tests/accessors/get_path_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var obj = void 0;
var moduleOpts = {
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;
}
};
QUnit.module('Ember.get with path', moduleOpts);
// ..........................................................
// 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);
});
});
QUnit.module('ESLint | ember-metal/tests/accessors/get_path_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/accessors/get_path_test.js should pass ESLint\n\n');
});
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, []), {});
});
});
QUnit.module('ESLint | ember-metal/tests/accessors/get_properties_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/accessors/get_properties_test.js should pass ESLint\n\n');
});
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, set) {
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 attempts 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 attempts 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 attempts 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 (get, set) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/accessors/get_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/accessors/get_test.js should pass ESLint\n\n');
});
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'));
});
});
QUnit.module('ESLint | ember-metal/tests/accessors/is_global_path_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/accessors/is_global_path_test.js should pass ESLint\n\n');
});
enifed('ember-metal/tests/accessors/mandatory_setters_test', ['ember/features', 'ember-metal'], function (_features, _emberMetal) {
'use strict';
QUnit.module('mandatory-setters');
function hasMandatorySetter(object, property) {
try {
return Object.getOwnPropertyDescriptor(object, property).set.isMandatorySetter === true;
} catch (e) {
return false;
}
}
function hasMetaValue(object, property) {
return (0, _emberMetal.meta)(object).peekValues(property) !== undefined;
}
if (_features.MANDATORY_SETTER) {
QUnit.test('does not assert if property is not being watched', function () {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
obj.someProp = 'blastix';
equal((0, _emberMetal.get)(obj, 'someProp'), 'blastix');
});
QUnit.test('should not setup mandatory-setter if property is not writable', function () {
expect(6);
var obj = {};
Object.defineProperty(obj, 'a', { value: true });
Object.defineProperty(obj, 'b', { value: false });
Object.defineProperty(obj, 'c', { value: undefined });
Object.defineProperty(obj, 'd', { value: undefined, writable: false });
Object.defineProperty(obj, 'e', { value: undefined, configurable: false });
Object.defineProperty(obj, 'f', { value: undefined, configurable: true });
(0, _emberMetal.watch)(obj, 'a');
(0, _emberMetal.watch)(obj, 'b');
(0, _emberMetal.watch)(obj, 'c');
(0, _emberMetal.watch)(obj, 'd');
(0, _emberMetal.watch)(obj, 'e');
(0, _emberMetal.watch)(obj, 'f');
ok(!hasMandatorySetter(obj, 'a'), 'mandatory-setter should not be installed');
ok(!hasMandatorySetter(obj, 'b'), 'mandatory-setter should not be installed');
ok(!hasMandatorySetter(obj, 'c'), 'mandatory-setter should not be installed');
ok(!hasMandatorySetter(obj, 'd'), 'mandatory-setter should not be installed');
ok(!hasMandatorySetter(obj, 'e'), 'mandatory-setter should not be installed');
ok(!hasMandatorySetter(obj, 'f'), 'mandatory-setter should not be installed');
});
QUnit.test('should not teardown non mandatory-setter descriptor', function () {
expect(1);
var obj = { get a() {
return 'hi';
} };
(0, _emberMetal.watch)(obj, 'a');
(0, _emberMetal.unwatch)(obj, 'a');
equal(obj.a, 'hi');
});
QUnit.test('should not confuse non descriptor watched gets', function () {
expect(2);
var obj = { get a() {
return 'hi';
} };
(0, _emberMetal.watch)(obj, 'a');
equal((0, _emberMetal.get)(obj, 'a'), 'hi');
equal(obj.a, 'hi');
});
QUnit.test('should not setup mandatory-setter if setter is already setup on property', function () {
expect(2);
var obj = { someProp: null };
Object.defineProperty(obj, 'someProp', {
get: function () {
return null;
},
set: function (value) {
equal(value, 'foo-bar', 'custom setter was called');
}
});
(0, _emberMetal.watch)(obj, 'someProp');
ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed');
obj.someProp = 'foo-bar';
});
QUnit.test('watched ES5 setter should not be smashed by mandatory setter', function () {
var value = void 0;
var obj = {
get foo() {},
set foo(_value) {
value = _value;
}
};
(0, _emberMetal.watch)(obj, 'foo');
(0, _emberMetal.set)(obj, 'foo', 2);
equal(value, 2);
});
QUnit.test('should not setup mandatory-setter if setter is already setup on property in parent prototype', function () {
expect(2);
function Foo() {}
Object.defineProperty(Foo.prototype, 'someProp', {
get: function () {
return null;
},
set: function (value) {
equal(value, 'foo-bar', 'custom setter was called');
}
});
var obj = new Foo();
(0, _emberMetal.watch)(obj, 'someProp');
ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed');
obj.someProp = 'foo-bar';
});
QUnit.test('should not setup mandatory-setter if setter is already setup on property in grandparent prototype', function () {
expect(2);
function Foo() {}
Object.defineProperty(Foo.prototype, 'someProp', {
get: function () {
return null;
},
set: function (value) {
equal(value, 'foo-bar', 'custom setter was called');
}
});
function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
Bar.prototype.constructor = Bar;
var obj = new Bar();
(0, _emberMetal.watch)(obj, 'someProp');
ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed');
obj.someProp = 'foo-bar';
});
QUnit.test('should not setup mandatory-setter if setter is already setup on property in great grandparent prototype', function () {
expect(2);
function Foo() {}
Object.defineProperty(Foo.prototype, 'someProp', {
get: function () {
return null;
},
set: function (value) {
equal(value, 'foo-bar', 'custom setter was called');
}
});
function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
Bar.prototype.constructor = Bar;
function Qux() {}
Qux.prototype = Object.create(Bar.prototype);
Qux.prototype.constructor = Qux;
var obj = new Qux();
(0, _emberMetal.watch)(obj, 'someProp');
ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed');
obj.someProp = 'foo-bar';
});
QUnit.test('should assert if set without Ember.set when property is being watched', function () {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
(0, _emberMetal.watch)(obj, 'someProp');
expectAssertion(function () {
obj.someProp = 'foo-bar';
}, 'You must use Ember.set() to set the `someProp` property (of custom-object) to `foo-bar`.');
});
QUnit.test('should not assert if set with Ember.set when property is being watched', function () {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
(0, _emberMetal.watch)(obj, 'someProp');
(0, _emberMetal.set)(obj, 'someProp', 'foo-bar');
equal((0, _emberMetal.get)(obj, 'someProp'), 'foo-bar');
});
QUnit.test('does not setup mandatory-setter if non-configurable', function () {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
Object.defineProperty(obj, 'someProp', {
configurable: false,
enumerable: true,
value: 'blastix'
});
(0, _emberMetal.watch)(obj, 'someProp');
ok(!hasMandatorySetter(obj, 'someProp'), 'blastix');
});
QUnit.test('ensure after watch the property is restored (and the value is no-longer stored in meta) [non-enumerable]', function () {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
Object.defineProperty(obj, 'someProp', {
configurable: true,
enumerable: false,
value: 'blastix'
});
(0, _emberMetal.watch)(obj, 'someProp');
equal(hasMandatorySetter(obj, 'someProp'), true, 'should have a mandatory setter');
var descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
equal(descriptor.enumerable, false, 'property should remain non-enumerable');
equal(descriptor.configurable, true, 'property should remain configurable');
equal(obj.someProp, 'blastix', 'expected value to be the getter');
equal(descriptor.value, undefined, 'expected existing value to NOT remain');
ok(hasMetaValue(obj, 'someProp'), 'someProp is stored in meta.values');
(0, _emberMetal.unwatch)(obj, 'someProp');
ok(!hasMetaValue(obj, 'someProp'), 'someProp is no longer stored in meta.values');
descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
equal(hasMandatorySetter(obj, 'someProp'), false, 'should no longer have a mandatory setter');
equal(descriptor.enumerable, false, 'property should remain non-enumerable');
equal(descriptor.configurable, true, 'property should remain configurable');
equal(obj.someProp, 'blastix', 'expected value to be the getter');
equal(descriptor.value, 'blastix', 'expected existing value to remain');
obj.someProp = 'new value';
// make sure the descriptor remains correct (nothing funky, like a redefined, happened in the setter);
descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
equal(descriptor.enumerable, false, 'property should remain non-enumerable');
equal(descriptor.configurable, true, 'property should remain configurable');
equal(descriptor.value, 'new value', 'expected existing value to NOT remain');
equal(obj.someProp, 'new value', 'expected value to be the getter');
equal(obj.someProp, 'new value');
});
QUnit.test('ensure after watch the property is restored (and the value is no-longer stored in meta) [enumerable]', function () {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
Object.defineProperty(obj, 'someProp', {
configurable: true,
enumerable: true,
value: 'blastix'
});
(0, _emberMetal.watch)(obj, 'someProp');
equal(hasMandatorySetter(obj, 'someProp'), true, 'should have a mandatory setter');
var descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
equal(descriptor.enumerable, true, 'property should remain enumerable');
equal(descriptor.configurable, true, 'property should remain configurable');
equal(obj.someProp, 'blastix', 'expected value to be the getter');
equal(descriptor.value, undefined, 'expected existing value to NOT remain');
ok(hasMetaValue(obj, 'someProp'), 'someProp is stored in meta.values');
(0, _emberMetal.unwatch)(obj, 'someProp');
ok(!hasMetaValue(obj, 'someProp'), 'someProp is no longer stored in meta.values');
descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
equal(hasMandatorySetter(obj, 'someProp'), false, 'should no longer have a mandatory setter');
equal(descriptor.enumerable, true, 'property should remain enumerable');
equal(descriptor.configurable, true, 'property should remain configurable');
equal(obj.someProp, 'blastix', 'expected value to be the getter');
equal(descriptor.value, 'blastix', 'expected existing value to remain');
obj.someProp = 'new value';
// make sure the descriptor remains correct (nothing funky, like a redefined, happened in the setter);
descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
equal(descriptor.enumerable, true, 'property should remain enumerable');
equal(descriptor.configurable, true, 'property should remain configurable');
equal(descriptor.value, 'new value', 'expected existing value to NOT remain');
equal(obj.someProp, 'new value');
});
QUnit.test('sets up mandatory-setter if property comes from prototype', function () {
expect(2);
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
var obj2 = Object.create(obj);
(0, _emberMetal.watch)(obj2, 'someProp');
ok(hasMandatorySetter(obj2, 'someProp'), 'mandatory setter has been setup');
expectAssertion(function () {
obj2.someProp = 'foo-bar';
}, 'You must use Ember.set() to set the `someProp` property (of custom-object) to `foo-bar`.');
});
QUnit.test('inheritance remains live', function () {
function Parent() {}
Parent.prototype.food = 'chips';
var child = new Parent();
equal(child.food, 'chips');
(0, _emberMetal.watch)(child, 'food');
equal(child.food, 'chips');
Parent.prototype.food = 'icecreame';
equal(child.food, 'icecreame');
(0, _emberMetal.unwatch)(child, 'food');
equal(child.food, 'icecreame');
Parent.prototype.food = 'chips';
equal(child.food, 'chips');
});
QUnit.test('inheritance remains live and preserves this', function () {
function Parent(food) {
this._food = food;
}
Object.defineProperty(Parent.prototype, 'food', {
get: function () {
return this._food;
}
});
var child = new Parent('chips');
equal(child.food, 'chips');
(0, _emberMetal.watch)(child, 'food');
equal(child.food, 'chips');
child._food = 'icecreame';
equal(child.food, 'icecreame');
(0, _emberMetal.unwatch)(child, 'food');
equal(child.food, 'icecreame');
var foodDesc = Object.getOwnPropertyDescriptor(Parent.prototype, 'food');
ok(!foodDesc.configurable, 'Parent.prototype.food desc should be non configable');
ok(!foodDesc.enumerable, 'Parent.prototype.food desc should be non enumerable');
equal(foodDesc.get.call({
_food: 'hi'
}), 'hi');
equal(foodDesc.set, undefined);
equal(child.food, 'icecreame');
});
}
});
QUnit.module('ESLint | ember-metal/tests/accessors/mandatory_setters_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/accessors/mandatory_setters_test.js should pass ESLint\n\n');
});
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 () {
var exceptionMessage = 'Property set failed: object in path \"bla\" could not be found or was destroyed.';
try {
(0, _emberMetal.set)(obj, 'bla.bla', 'BAM');
} catch (ex) {
equal(ex.message, exceptionMessage);
}
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/accessors/set_path_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/accessors/set_path_test.js should pass ESLint\n\n');
});
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 (key, value) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/accessors/set_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/accessors/set_test.js should pass ESLint\n\n');
});
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);
}
});
QUnit.module('ESLint | ember-metal/tests/alias_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/alias_test.js should pass ESLint\n\n');
});
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 (get, set) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/binding/connect_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/binding/connect_test.js should pass ESLint\n\n');
});
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 (key) {
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, set) {
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');
});
});
});
QUnit.module('ESLint | ember-metal/tests/binding/sync_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/binding/sync_test.js should pass ESLint\n\n');
});
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 (key) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/cache_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/cache_test.js should pass ESLint\n\n');
});
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 () {
function didChange() {}
var obj = {};
(0, _emberMetal.addObserver)(obj, 'foo.bar', null, didChange);
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);
});
});
QUnit.module('ESLint | ember-metal/tests/chains_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/chains_test.js should pass ESLint\n\n');
});
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 (key, value) {
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, set) {
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, set) {
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, set) {
(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 (key, value) {
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, set) {
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 (key, value) {
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 (key) {
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 (key) {
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 (get, set) {
expectAssertion(function () {
(0, _emberMetal.defineProperty)(obj, 'roo', (0, _emberMetal.computed)(function (key) {
count++;
return 'roo ' + count;
}).property('fee.{bar, baz,bop , }'));
}, /cannot contain spaces/);
});
(0, _internalTestHelpers.testBoth)('throws an assertion if an uncached `get` is called after object is destroyed', function (get, set) {
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
var meta = (0, _emberMetal.meta)(obj);
meta.destroy();
obj.toString = function () {
return '';
};
expectAssertion(function () {
get(obj, 'foo', 'bar');
}, 'Cannot modify dependent keys for `foo` on `` after it has been destroyed.');
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'deps were not updated');
});
// ..........................................................
// CHAINED DEPENDENT KEYS
//
var func = void 0;
var moduleOpts = {
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;
}
};
QUnit.module('computed - dependentkey with chained properties', moduleOpts);
(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 (get, set) {
(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 (keyName) {
ok(false, 'The getter should not be invoked');
return 'get-value';
},
set: function (keyName, value, oldValue) {
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 (key) {
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 (key) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/computed_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/computed_test.js should pass ESLint\n\n');
});
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 test(title, callback) {
var _this = this;
QUnit.test(title, function (assert) {
callback(assert, new _this(assert));
});
};
function DescriptorTest(assert) {
(0, _emberBabel.classCallCheck)(this, DescriptorTest);
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 module(title) {
QUnit.module(title + ': using defineProperty on an object directly');
};
function _class(assert) {
(0, _emberBabel.classCallCheck)(this, _class);
var _this2 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest.call(this, assert));
_this2.object = {};
return _this2;
}
_class.prototype.install = function install(key, desc) {
var object = this.object,
assert = this.assert;
(0, _emberMetal.defineProperty)(object, key, desc);
assert.ok(object.hasOwnProperty(key));
};
_class.prototype.set = function set(key, value) {
this.object[key] = value;
};
_class.prototype.finalize = function finalize() {
return this.object;
};
_class.prototype.source = function source() {
return this.object;
};
return _class;
}(DescriptorTest), function (_DescriptorTest2) {
(0, _emberBabel.inherits)(_class2, _DescriptorTest2);
_class2.module = function module(title) {
QUnit.module(title + ': using defineProperty on a prototype');
};
function _class2(assert) {
(0, _emberBabel.classCallCheck)(this, _class2);
var _this3 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest2.call(this, assert));
_this3.proto = {};
return _this3;
}
_class2.prototype.install = function install(key, desc) {
var proto = this.proto,
assert = this.assert;
(0, _emberMetal.defineProperty)(proto, key, desc);
assert.ok(proto.hasOwnProperty(key));
};
_class2.prototype.set = function set(key, value) {
this.proto[key] = value;
};
_class2.prototype.finalize = function finalize() {
return Object.create(this.proto);
};
_class2.prototype.source = function source() {
return this.proto;
};
return _class2;
}(DescriptorTest), function (_DescriptorTest3) {
(0, _emberBabel.inherits)(_class3, _DescriptorTest3);
_class3.module = function module(title) {
QUnit.module(title + ': in EmberObject.extend()');
};
function _class3(assert) {
(0, _emberBabel.classCallCheck)(this, _class3);
var _this4 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest3.call(this, assert));
_this4.klass = null;
_this4.props = {};
return _this4;
}
_class3.prototype.install = function install(key, desc) {
this.props[key] = desc;
};
_class3.prototype.set = function set(key, value) {
this.props[key] = value;
};
_class3.prototype.finalize = function finalize() {
this.klass = _emberRuntime.Object.extend(this.props);
return this.klass.create();
};
_class3.prototype.source = function source() {
return this.klass.prototype;
};
return _class3;
}(DescriptorTest), function (_DescriptorTest4) {
(0, _emberBabel.inherits)(_class4, _DescriptorTest4);
_class4.module = function module(title) {
QUnit.module(title + ': in EmberObject.extend() through a mixin');
};
function _class4(assert) {
(0, _emberBabel.classCallCheck)(this, _class4);
var _this5 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest4.call(this, assert));
_this5.klass = null;
_this5.props = {};
return _this5;
}
_class4.prototype.install = function install(key, desc) {
this.props[key] = desc;
};
_class4.prototype.set = function set(key, value) {
this.props[key] = value;
};
_class4.prototype.finalize = function finalize() {
this.klass = _emberRuntime.Object.extend(_emberMetal.Mixin.create(this.props));
return this.klass.create();
};
_class4.prototype.source = function source() {
return this.klass.prototype;
};
return _class4;
}(DescriptorTest), function (_DescriptorTest5) {
(0, _emberBabel.inherits)(_class5, _DescriptorTest5);
_class5.module = function module(title) {
QUnit.module(title + ': inherited from another EmberObject super class');
};
function _class5(assert) {
(0, _emberBabel.classCallCheck)(this, _class5);
var _this6 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest5.call(this, assert));
_this6.superklass = null;
_this6.props = {};
return _this6;
}
_class5.prototype.install = function install(key, desc) {
this.props[key] = desc;
};
_class5.prototype.set = function set(key, value) {
this.props[key] = value;
};
_class5.prototype.finalize = function finalize() {
this.superklass = _emberRuntime.Object.extend(this.props);
return this.superklass.extend().create();
};
_class5.prototype.source = function source() {
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');
});
});
});
QUnit.module('ESLint | ember-metal/tests/descriptor_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/descriptor_test.js should pass ESLint\n\n');
});
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);
function callback() {
/*jshint validthis:true */
equal(this, target);
(0, _emberMetal.sendEvent)(obj, 'event!');
return 'result';
}
(0, _emberMetal.sendEvent)(obj, 'event!');
equal((0, _emberMetal.suspendListener)(obj, 'event!', target, target.method, callback), '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 = {};
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!');
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 overridden property');
(0, _emberMetal.sendEvent)(obj, 'baz');
equal(triggered, 1, 'should invoke from subclass property');
});
});
QUnit.module('ESLint | ember-metal/tests/events_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/events_test.js should pass ESLint\n\n');
});
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);
var expected = ['a', 'b', 'c'];
deepEqual(expected.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);
var expected = ['a.b.e', 'a.c.e', 'a.d.e'];
deepEqual(expected.sort(), foundProperties.sort());
});
QUnit.test('Multiple brace expansions work correctly', function () {
expect(1);
(0, _emberMetal.expandProperties)('{a,b,c}.d.{e,f}.g', addProperty);
var expected = ['a.d.e.g', 'a.d.f.g', 'b.d.e.g', 'b.d.f.g', 'c.d.e.g', 'c.d.f.g'];
deepEqual(expected.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);
var expected = ['a.d.e', 'a.d.f', 'b.d.e', 'b.d.f', 'c.d.e', 'c.d.f'];
deepEqual(expected.sort(), foundProperties.sort());
});
QUnit.test('Nested brace expansions are not allowed', function () {
var nestedBraceProperties = ['a.{b.{c,d}}', 'a.{{b}.c}', 'a.{b,c}.{d.{e,f}.g', 'a.{b.{c}', 'a.{b,c}}', 'model.{bar,baz'];
nestedBraceProperties.forEach(function (invalidProperties) {
expectAssertion(function () {
return (0, _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}"/);
});
});
QUnit.module('ESLint | ember-metal/tests/expand_properties_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/expand_properties_test.js should pass ESLint\n\n');
});
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 overridden 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');
});
});
QUnit.module('ESLint | ember-metal/tests/injected_property_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/injected_property_test.js should pass ESLint\n\n');
});
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 (name, timestamp, payload) {
return passthru1;
},
after: function (name, timestamp, payload, beforeValue) {
strictEqual(beforeValue, passthru1);
}
});
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function (name, timestamp, payload) {
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 () {});
});
});
QUnit.module('ESLint | ember-metal/tests/instrumentation_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/instrumentation_test.js should pass ESLint\n\n');
});
enifed('ember-metal/tests/is_blank_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isBlank');
QUnit.test('Ember.isBlank', function () {
var string = 'string';
var fn = function () {};
var object = { length: 0 };
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)(fn), '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)(object), 'for an Object that has zero \'length\'');
equal(false, (0, _emberMetal.isBlank)([1, 2, 3]), 'for a non-empty array');
});
});
QUnit.module('ESLint | ember-metal/tests/is_blank_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/is_blank_test.js should pass ESLint\n\n');
});
enifed('ember-metal/tests/is_empty_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isEmpty');
QUnit.test('Ember.isEmpty', function () {
var string = 'string';
var fn = function () {};
var object = { length: 0 };
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)(fn), '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)(object), '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');
});
});
QUnit.module('ESLint | ember-metal/tests/is_empty_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/is_empty_test.js should pass ESLint\n\n');
});
enifed('ember-metal/tests/is_none_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isNone');
QUnit.test('Ember.isNone', function () {
var string = 'string';
var fn = 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)(fn), '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');
});
});
QUnit.module('ESLint | ember-metal/tests/is_none_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/is_none_test.js should pass ESLint\n\n');
});
enifed('ember-metal/tests/is_present_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isPresent');
QUnit.test('Ember.isPresent', function () {
var string = 'string';
var fn = function () {};
var object = { length: 0 };
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)(fn), '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)(object), 'for an Object that has zero \'length\'');
equal(true, (0, _emberMetal.isPresent)([1, 2, 3]), 'for a non-empty array');
});
});
QUnit.module('ESLint | ember-metal/tests/is_present_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/is_present_test.js should pass ESLint\n\n');
});
enifed('ember-metal/tests/libraries_test', ['ember-debug', 'ember-metal', 'ember/features'], function (_emberDebug, _emberMetal, _features) {
'use strict';
var libs = void 0,
registry = void 0; /* globals EmberDev */
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);
});
if (_features.EMBER_LIBRARIES_ISREGISTERED) {
QUnit.test('isRegistered returns correct value', function () {
expect(3);
equal(libs.isRegistered('magic'), false);
libs.register('magic', 1.23);
equal(libs.isRegistered('magic'), true);
libs.deRegister('magic');
equal(libs.isRegistered('magic'), false);
});
}
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);
});
});
QUnit.module('ESLint | ember-metal/tests/libraries_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/libraries_test.js should pass ESLint\n\n');
});
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.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.');
});
});
QUnit.module('ESLint | ember-metal/tests/main_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/main_test.js should pass ESLint\n\n');
});
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;
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) {
theMap = theMap || map;
for (var 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 (var 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');
});
});
QUnit.module('ESLint | ember-metal/tests/map_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/map_test.js should pass ESLint\n\n');
});
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);
});
QUnit.test('meta.writeWatching issues useful error after destroy', function (assert) {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _emberMetal.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writeWatching('hello', 1);
}, 'Cannot update watchers for `hello` on `` after it has been destroyed.');
});
QUnit.test('meta.writableTag issues useful error after destroy', function (assert) {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _emberMetal.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writableTag(function () {});
}, 'Cannot create a new tag for `` after it has been destroyed.');
});
QUnit.test('meta.writableChainWatchers issues useful error after destroy', function (assert) {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _emberMetal.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writableChainWatchers(function () {});
}, 'Cannot create a new chain watcher for `` after it has been destroyed.');
});
QUnit.test('meta.writableChains issues useful error after destroy', function (assert) {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _emberMetal.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writableChains(function () {});
}, 'Cannot create a new chains for `` after it has been destroyed.');
});
QUnit.test('meta.writeValues issues useful error after destroy', function (assert) {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _emberMetal.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writeValues('derp', 'ohai');
}, 'Cannot set the value of `derp` on `` after it has been destroyed.');
});
QUnit.test('meta.writeDeps issues useful error after destroy', function (assert) {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _emberMetal.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writeDeps('derp', 'ohai', 1);
}, 'Cannot modify dependent keys for `ohai` on `` after it has been destroyed.');
});
});
QUnit.module('ESLint | ember-metal/tests/meta_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/meta_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/alias_method_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/alias_method_test.js should pass ESLint\n\n');
});
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'), '');
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/apply_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/apply_test.js should pass ESLint\n\n');
});
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 (key) {
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 (key) {
superGetOccurred = true;
},
set: function (key, value) {
superSetOccurred = true;
}
})
});
SubMixin = _emberMetal.Mixin.create(SuperMixin, {
aProp: (0, _emberMetal.computed)({
get: function (key) {
return this._super.apply(this, arguments);
},
set: function (key, value) {
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 (k, v) {
cpWasCalled = true;
}
}),
cpWithSetter3: (0, _emberMetal.computed)({
get: K,
set: function (k, v) {
cpWasCalled = true;
}
}),
cpWithoutSetter: (0, _emberMetal.computed)(function (k) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/computed_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/computed_test.js should pass ESLint\n\n');
});
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']);
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/concatenated_properties_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/concatenated_properties_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/detect_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/detect_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/introspection_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/introspection_test.js should pass ESLint\n\n');
});
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 (a) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/merged_properties_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/merged_properties_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/method_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/method_test.js should pass ESLint\n\n');
});
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 overridden 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')
});
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/observer_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/observer_test.js should pass ESLint\n\n');
});
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!');
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/reopen_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/reopen_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/required_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/required_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/mixin/without_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/mixin/without_test.js should pass ESLint\n\n');
});
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 assert to invalid input', function (get, set) {
expectAssertion(function () {
(0, _emberMetal.observer)(function () {});
}, 'Ember.observer called without valid path');
expectDeprecation('Passing the dependentKeys after the callback function in Ember.observer is deprecated. Ensure the callback function is the last argument.');
expectAssertion(function () {
(0, _emberMetal.observer)(null);
}, 'Ember.observer called without a function');
});
(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, set) {
var observerCount = 0;
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 (var 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 obj3 = { foo: foo };
var obj4 = { foo: foo };
var count1 = 0;
var count2 = 0;
var count3 = 0;
var count4 = 0;
function observer1() {
count1++;
}
function observer2() {
count2++;
}
function observer3() {
count3++;
(0, _emberMetal.removeObserver)(obj1, 'foo.bar', observer1);
(0, _emberMetal.removeObserver)(obj2, 'foo.bar', observer2);
(0, _emberMetal.removeObserver)(obj4, 'foo.bar', observer4);
}
function observer4() {
count4++;
}
(0, _emberMetal.addObserver)(obj1, 'foo.bar', observer1);
(0, _emberMetal.addObserver)(obj2, 'foo.bar', observer2);
(0, _emberMetal.addObserver)(obj3, 'foo.bar', observer3);
(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 obj3 = { foo: foo };
var obj4 = { foo: foo };
var count1 = 0;
var count2 = 0;
var count3 = 0;
var count4 = 0;
function observer1() {
count1++;
}
function observer2() {
count2++;
}
function observer3() {
count3++;
(0, _emberMetal._removeBeforeObserver)(obj1, 'foo.bar', observer1);
(0, _emberMetal._removeBeforeObserver)(obj2, 'foo.bar', observer2);
(0, _emberMetal._removeBeforeObserver)(obj4, 'foo.bar', observer4);
}
function observer4() {
count4++;
}
(0, _emberMetal._addBeforeObserver)(obj1, 'foo.bar', observer1);
(0, _emberMetal._addBeforeObserver)(obj2, 'foo.bar', observer2);
(0, _emberMetal._addBeforeObserver)(obj3, 'foo.bar', observer3);
(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);
function callback() {
/*jshint validthis:true */
equal(this, target);
set(obj, 'foo', '2');
return 'result';
}
set(obj, 'foo', '1');
equal((0, _emberMetal._suspendObserver)(obj, 'foo', target, target.method, callback), '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);
function callback() {
/*jshint validthis:true */
equal(this, target);
set(obj, 'foo', '2');
return 'result';
}
set(obj, 'foo', '1');
(0, _emberMetal.beginPropertyChanges)();
equal((0, _emberMetal._suspendObserver)(obj, 'foo', target, target.method, callback), '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);
function callback() {
/*jshint validthis:true */
equal(this, target);
set(obj, 'foo', '2');
return 'result';
}
set(obj, 'foo', '1');
equal((0, _emberMetal._suspendObservers)(obj, ['foo'], target, target.method, callback), '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);
function callback() {
/*jshint validthis:true */
equal(this, target);
set(obj, 'foo', '2');
return 'result';
}
set(obj, 'foo', '1');
(0, _emberMetal.beginPropertyChanges)();
equal((0, _emberMetal._suspendObservers)(obj, ['foo'], target, target.method, callback), '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 (obj, keyName, value) {
this.count++;
}
};
var target2 = {
count: 0,
didChange: function (obj, keyName, value) {
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 (key) {
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 (get, set) {
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 (get, set) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/observer_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/observer_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/performance_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/performance_test.js should pass ESLint\n\n');
});
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);
var obj = {
didDefineProperty: function (obj, keyName, value) {
equal(keyName, 'foo', 'key name should be foo');
equal(value, 'bar', 'value should be bar');
}
};
(0, _emberMetal.defineProperty)(obj, '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;
});
var obj = {
didDefineProperty: function (obj, keyName, value) {
equal(keyName, 'foo', 'key name should be foo');
strictEqual(value, computedProperty, 'value should be passed as computed property');
}
};
(0, _emberMetal.defineProperty)(obj, '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
};
var obj = {
didDefineProperty: function (obj, keyName, value) {
equal(keyName, 'answer', 'key name should be answer');
strictEqual(value, descriptor, 'value should be passed as descriptor');
}
};
(0, _emberMetal.defineProperty)(obj, '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');
});
});
QUnit.module('ESLint | ember-metal/tests/properties_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/properties_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/property_did_change_hook.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/property_did_change_hook.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/add_queue_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/add_queue_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/debounce_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/debounce_test.js should pass ESLint\n\n');
});
enifed('ember-metal/tests/run_loop/later_test', ['ember-utils', 'ember-metal'], function (_emberUtils, _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 = (0, _emberUtils.assign)({}, originalPlatform, {
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');
});
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/later_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/later_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/next_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/next_test.js should pass ESLint\n\n');
});
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');
});
});
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/once_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/once_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/onerror_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/onerror_test.js should pass ESLint\n\n');
});
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 asyncFunction(fn) {
fn(2, 3);
}
asyncFunction(_emberMetal.run.bind(asyncCallback, asyncCallback, 1));
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/run_bind_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/run_bind_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/run_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/run_test.js should pass ESLint\n\n');
});
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/);
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/schedule_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/schedule_test.js should pass ESLint\n\n');
});
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();
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/sync_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/sync_test.js should pass ESLint\n\n');
});
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;
});
});
QUnit.module('ESLint | ember-metal/tests/run_loop/unwind_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/run_loop/unwind_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-metal/tests/set_properties_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/set_properties_test.js should pass ESLint\n\n');
});
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, key, fn) {
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, key, fn) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/watching/is_watching_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/watching/is_watching_test.js should pass ESLint\n\n');
});
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 (get, set) {
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');
});
});
QUnit.module('ESLint | ember-metal/tests/watching/unwatch_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/watching/unwatch_test.js should pass ESLint\n\n');
});
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, set) {
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)');
});
});
QUnit.module('ESLint | ember-metal/tests/watching/watch_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/watching/watch_test.js should pass ESLint\n\n');
});
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 b = {};
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(b), 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]');
});
});
QUnit.module('ESLint | ember-metal/tests/weak_map_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-metal/tests/weak_map_test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/ext/controller.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/ext/controller.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/ext/run_loop.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/ext/run_loop.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/index.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/location/api.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/location/api.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/location/auto_location.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/location/auto_location.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/location/hash_location.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/location/hash_location.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/location/history_location.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/location/history_location.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/location/none_location.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/location/none_location.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/location/util.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/location/util.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/services/router.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/services/router.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/services/routing.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/services/routing.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/system/cache.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/system/cache.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/system/controller_for.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/system/controller_for.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/system/dsl.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/system/dsl.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/system/generate_controller.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/system/generate_controller.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/system/query_params.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/system/query_params.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/system/route.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/system/route.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/system/router.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/system/router.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/system/router_state.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/system/router_state.js should pass ESLint\n\n');
});
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 router = {
transitionTo: function (route) {
return route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var controller = _emberRuntime.Controller.create({ target: router });
(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');
});
QUnit.test('replaceRoute considers an engine\'s mountPoint', function () {
expect(4);
var router = {
replaceWith: function (route) {
return route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var controller = _emberRuntime.Controller.create({ target: router });
(0, _emberUtils.setOwner)(controller, engineInstance);
strictEqual(controller.replaceRoute('application'), 'foo.bar.application', 'properly prefixes application route');
strictEqual(controller.replaceRoute('posts'), 'foo.bar.posts', 'properly prefixes child routes');
throws(function () {
return controller.replaceRoute('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
strictEqual(controller.replaceRoute(queryParams), queryParams, 'passes query param only transitions through');
});
});
QUnit.module('ESLint | ember-routing/tests/ext/controller_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/ext/controller_test.js should pass ESLint\n\n');
});
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 (path) {
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');
});
});
QUnit.module('ESLint | ember-routing/tests/location/auto_location_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/location/auto_location_test.js should pass ESLint\n\n');
});
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')
});
var callback = function (param) {
equal(param, '/foo/bar', 'path is passed as param');
};
location.onUpdateURL(callback);
triggerHashchange();
});
QUnit.test('HashLocation.onUpdateURL doesn\'t execute callback if lastSetURL === path', function () {
expect(0);
createLocation({
_location: {
href: '/#/foo/bar'
},
lastSetURL: '/foo/bar'
});
var callback = function (param) {
ok(false, 'callback should not be called');
};
location.onUpdateURL(callback);
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();
var callback = function (param) {
ok(true, 'should invoke callback once');
};
location.onUpdateURL(callback);
triggerHashchange();
(0, _emberMetal.run)(location, 'destroy');
location = null;
triggerHashchange();
});
});
QUnit.module('ESLint | ember-routing/tests/location/hash_location_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/location/hash_location_test.js should pass ESLint\n\n');
});
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, title, url) {
this.state = state;
this._states[0] = state;
},
pushState: function (state, title, url) {
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(), '/');
});
});
QUnit.module('ESLint | ember-routing/tests/location/history_location_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/location/history_location_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-routing/tests/location/none_location_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/location/none_location_test.js should pass ESLint\n\n');
});
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;
var location = {
protocol: 'http:',
hostname: 'emberjs.com',
port: '1337',
replace: function (url) {
equal(url, expectedURL);
}
};
expectedURL = 'http://emberjs.com:1337//google.com';
(0, _util.replacePath)(location, '//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
});
QUnit.module('ESLint | ember-routing/tests/location/util_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/location/util_test.js should pass ESLint\n\n');
});
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 = {};
var defaultValue = {};
this.cache.stash('foo', 'bar', token);
assert.strictEqual(this.cache.lookup('foo', 'bar', defaultValue), token);
});
QUnit.test('lookup - returns default value if key does not exist in bucket', function (assert) {
var token = {};
var defaultValue = {};
this.cache.stash('foo', 'bar', token);
assert.strictEqual(this.cache.lookup('foo', 'boo', defaultValue), defaultValue);
assert.strictEqual(this.cache.lookup('foo', 'constructor', defaultValue), defaultValue);
});
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);
});
});
QUnit.module('ESLint | ember-routing/tests/system/cache_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/system/cache_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test controllerFor should lookup for registered controllers'] = function testControllerForShouldLookupForRegisteredControllers(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() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase2.apply(this, arguments));
}
_class2.prototype['@test generateController should return Ember.Controller'] = function testGenerateControllerShouldReturnEmberController(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 testGenerateControllerShouldReturnControllerBasicIfResolved(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 testGenerateControllerShouldReturnControllerBasicIfRegistered(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));
});
QUnit.module('ESLint | ember-routing/tests/system/controller_for_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/system/controller_for_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-routing/tests/system/dsl_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/system/dsl_test.js should pass ESLint\n\n');
});
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 (id) {
return post;
}
});
var ownerOptions = {
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();
}
};
}
}
};
(0, _emberUtils.setOwner)(route, (0, _internalTestHelpers.buildOwner)(ownerOptions));
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 () {
var model = { id: 2, firstName: 'Ned', lastName: 'Ryerson' };
deepEqual(route.serialize(model, ['firstName', 'lastName']), { firstName: 'Ned', lastName: 'Ryerson' }, 'serialized correctly');
});
QUnit.test('returns model.id if params include *_id', function () {
var model = { id: 2 };
deepEqual(route.serialize(model, ['post_id']), { post_id: 2 }, 'serialized correctly');
});
QUnit.test('returns checks for existence of model.post_id before trying model.id', function () {
var model = { post_id: 3 };
deepEqual(route.serialize(model, ['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('route._qp does not crash if the controller has no QP, or setProperties', function () {
lookupHash['controller:test'] = {};
routeOne.controllerName = 'test';
var qp = routeOne.get('_qp');
deepEqual(qp.map, {}, 'map should be empty');
deepEqual(qp.propertyNames, [], 'property names should be empty');
deepEqual(qp.qps, [], 'qps is should be empty');
});
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 router = {
transitionTo: function (route) {
return route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({ router: router });
(0, _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 router = {
intermediateTransitionTo: function (route) {
lastRoute = route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({ router: router });
(0, _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 router = {
replaceWith: function (route) {
return route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({ router: router });
(0, _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');
});
});
QUnit.module('ESLint | ember-routing/tests/system/route_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/system/route_test.js should pass ESLint\n\n');
});
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('[GH#15237] EmberError is imported correctly', function () {
// If we get the right message it means Error is being imported correctly.
throws(function () {
(0, _router.triggerEvent)(null, false, []);
}, /because your app hasn't finished transitioning/);
});
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');
var browserLocation = {
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.location = browserLocation;
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(s1, s2, s3) {
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;
var FakeLocation = {
cancelRouterSetup: true,
create: function () {
return this;
}
};
owner.register('location:fake', FakeLocation);
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);
var handlerInfos = [{
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;
}
}
}
}];
(0, _router.triggerEvent)(handlerInfos, 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');
});
});
QUnit.module('ESLint | ember-routing/tests/system/router_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/system/router_test.js should pass ESLint\n\n');
});
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 (assert) {
var paramName = 'foo';
var params = [paramName];
var normalized = (0, _utils.normalizeControllerQueryParams)(params);
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 (assert) {
var paramName = 'foo';
var params = [{ 'foo': 'an_alias' }];
var normalized = (0, _utils.normalizeControllerQueryParams)(params);
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 (assert) {
var paramName = 'foo';
var params = [{ 'foo': { as: 'an_alias' } }];
var normalized = (0, _utils.normalizeControllerQueryParams)(params);
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.module('ESLint | ember-routing/tests/utils_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/tests/utils_test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-routing/utils.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-routing/utils.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/compare.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/compare.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/computed/computed_macros.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/computed/computed_macros.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/computed/reduce_computed_macros.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/computed/reduce_computed_macros.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/controllers/controller.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/controllers/controller.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/copy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/copy.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/ext/function.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/ext/function.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/ext/rsvp.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/ext/rsvp.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/ext/string.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/ext/string.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/index.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/inject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/inject.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/is-equal.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/is-equal.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/-proxy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/-proxy.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/action_handler.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/action_handler.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/array.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/array.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/comparable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/comparable.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/container_proxy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/container_proxy.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/controller.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/controller.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/controller_content_model_alias_deprecation.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/controller_content_model_alias_deprecation.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/copyable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/copyable.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/enumerable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/enumerable.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/evented.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/evented.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/freezable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/freezable.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/mutable_array.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/mutable_array.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/mutable_enumerable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/mutable_enumerable.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/observable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/observable.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/promise_proxy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/promise_proxy.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/registry_proxy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/registry_proxy.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/mixins/target_action_support.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/mixins/target_action_support.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/string_registry.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/string_registry.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/application.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/application.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/array_proxy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/array_proxy.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/core_object.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/core_object.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/lazy_load.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/lazy_load.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/namespace.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/namespace.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/native_array.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/native_array.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/object.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/object.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/object_proxy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/object_proxy.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/service.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/service.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/system/string.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/system/string.js should pass ESLint\n\n');
});
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, set) {
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, set) {
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 (key) {
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 (key) {
return constantValue;
},
set: function (key, value) {
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 (get, set) {
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 (key) {
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);
});
});
QUnit.module('ESLint | ember-runtime/tests/computed/computed_macros_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/computed/computed_macros_test.js should pass ESLint\n\n');
});
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 () {
var array = ['a', 'b', 'c'];
obj = _object.default.extend({
mapped: (0, _reduce_computed_macros.map)('array', function (item, index) {
return index;
})
}).create({
array: array
});
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 asserts if given fewer or more than two dependent properties', function () {
expectAssertion(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])
});
}, /Ember\.computed\.setDiff requires exactly two dependent arrays/, 'setDiff requires two dependent arrays');
expectAssertion(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])
});
}, /Ember\.computed\.setDiff 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 jaime = {
fname: 'Jaime',
lname: 'Lannister',
age: 34
};
var items = obj.get('items');
items.replace(0, 1, jaime);
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 daria = { name: 'Daria' };
var jane = { name: 'Jane' };
var sisters = [jane, daria];
var sortProps = (0, _native_array.A)(['name']);
var jaime = _object.default.extend({
sortedPeople: (0, _reduce_computed_macros.sort)('sisters', 'sortProps'),
sortProps: sortProps
}).create({
sisters: sisters
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/computed/reduce_computed_macros_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/computed/reduce_computed_macros_test.js should pass ESLint\n\n');
});
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('controller:bar', _object.default.extend());
owner.register('foo:main', AnObject);
owner.lookup('foo:main');
}, /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');
});
});
QUnit.module('ESLint | ember-runtime/tests/controllers/controller_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/controllers/controller_test.js should pass ESLint\n\n');
});
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)');
});
});
QUnit.module('ESLint | ember-runtime/tests/core/compare_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/core/compare_test.js should pass ESLint\n\n');
});
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 () {
var obj = { field: null };
equal((0, _copy.default)(obj, 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');
});
});
QUnit.module('ESLint | ember-runtime/tests/core/copy_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/core/copy_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/core/isEqual_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/core/isEqual_test.js should pass ESLint\n\n');
});
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 numarray = [1, 2, 3];
var number = 23;
var strarray = ['Hello', 'Hi'];
var string = 'Hello';
var object = {};
var length = { length: 12 };
var strangeLength = { length: 'yes' };
var fn = function () {};
var arrayProxy = _array_proxy.default.create({ content: (0, _native_array.A)() });
equal((0, _utils.isArray)(numarray), true, '[1,2,3]');
equal((0, _utils.isArray)(number), false, '23');
equal((0, _utils.isArray)(strarray), true, '["Hello", "Hi"]');
equal((0, _utils.isArray)(string), false, '"Hello"');
equal((0, _utils.isArray)(object), false, '{}');
equal((0, _utils.isArray)(length), true, '{ length: 12 }');
equal((0, _utils.isArray)(strangeLength), false, '{ length: "yes" }');
equal((0, _utils.isArray)(global), false, 'global');
equal((0, _utils.isArray)(fn), 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');
});
}
});
QUnit.module('ESLint | ember-runtime/tests/core/is_array_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/core/is_array_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/core/is_empty_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/core/is_empty_test.js should pass ESLint\n\n');
});
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 object = { a: 'b' };
var a = null;
var arr = [1, 2, 3];
var obj = {};
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)(object), 'object', 'object');
equal((0, _utils.typeOf)(undefined), 'undefined', 'item of type undefined');
equal((0, _utils.typeOf)(a), 'null', 'item of type null');
equal((0, _utils.typeOf)(arr), 'array', 'item of type array');
equal((0, _utils.typeOf)(obj), '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');
});
}
});
QUnit.module('ESLint | ember-runtime/tests/core/type_of_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/core/type_of_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/ext/function_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/ext/function_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/ext/mixin_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/ext/mixin_test.js should pass ESLint\n\n');
});
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 (resolve, reject) {
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);
var fakeTransitionAbort = { name: 'TransitionAborted' };
(0, _emberMetal.run)(_rsvp.default, 'reject', fakeTransitionAbort);
ok(true, 'did not throw an error when dealing with TransitionAborted');
});
QUnit.test('Can reject with non-Error object', function (assert) {
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 (assert) {
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)();
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');
});
var actualError = new Error('OMG what really happened');
var 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)();
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');
});
var actualError = 'OMG what really happened';
var 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)();
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');
});
var 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(something) {
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);
});
});
QUnit.module('ESLint | ember-runtime/tests/ext/rsvp_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/ext/rsvp_test.js should pass ESLint\n\n');
});
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);
owner.register('foo:bar', _object.default.extend());
owner.register('foo:baz', _object.default.extend());
expect(1);
owner.lookup('foo:main');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/inject_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/inject_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/mixins/observable/chained_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/mixins/observable/chained_test.js should pass ESLint\n\n');
});
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, value) {
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, value) {
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 () {
var foo = {
bar: {
baz: 'blargh'
}
};
equal((0, _emberMetal.get)(foo, 'bar.baz'), 'blargh');
});
// ..........................................................
// SET()
//
QUnit.module('object.set()', {
setup: function () {
object = ObservableObject.extend({
computed: (0, _emberMetal.computed)({
get: function (key) {
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 (key) {
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 (key) {
(0, _emberMetal.get)(this, 'inc');
return this.nestedIncCallCount++;
}).property('inc'),
isOn: (0, _emberMetal.computed)({
get: function () {
return this.get('state') === 'on';
},
set: function (key, value) {
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 (key, value) {
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'];
var ret = [];
for (var idx = 0; idx < keys.length; idx++) {
ret[ret.length] = this.get(keys[idx]);
}
return ret;
},
newObserver: function () {
this.abnormal = 'changedValueObserved';
},
testObserver: (0, _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 (target, key, value) {
callCount++;
});
(0, _emberMetal.run)(function () {
obj.foo.set('bar', null);
});
equal(callCount, 1, 'changing bar should trigger observer');
expect(1);
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/mixins/observable/observable_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/mixins/observable/observable_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/mixins/observable/observersForKey_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/mixins/observable/observersForKey_test.js should pass ESLint\n\n');
});
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, value, rev) {
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/system/binding_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/system/binding_test.js should pass ESLint\n\n');
});
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()));
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/system/object/base_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/system/object/base_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/system/object/bindings_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/system/object/bindings_test.js should pass ESLint\n\n');
});
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 mixin = {
values: ['d', 'e']
};
var subKlass = klass.extend(mixin, {
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 + ')');
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/system/object/concatenated_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/system/object/concatenated_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/legacy_1x/system/run_loop_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/legacy_1x/system/run_loop_test.js should pass ESLint\n\n');
});
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']);
});
});
QUnit.module('ESLint | ember-runtime/tests/main_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/main_test.js should pass ESLint\n\n');
});
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 (idx) {
(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');
});
});
QUnit.module('ESLint | ember-runtime/tests/mixins/array_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/array_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-runtime/tests/mixins/comparable_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/comparable_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/mixins/container_proxy_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/container_proxy_test.js should pass ESLint\n\n');
});
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();
});
QUnit.module('ESLint | ember-runtime/tests/mixins/copyable_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/copyable_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-runtime/tests/mixins/enumerable_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/enumerable_test.js should pass ESLint\n\n');
});
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();
});
});
QUnit.module('ESLint | ember-runtime/tests/mixins/freezable_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/freezable_test.js should pass ESLint\n\n');
});
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();
});
QUnit.module('ESLint | ember-runtime/tests/mixins/mutable_array_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/mutable_array_test.js should pass ESLint\n\n');
});
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();
});
QUnit.module('ESLint | ember-runtime/tests/mixins/mutable_enumerable_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/mutable_enumerable_test.js should pass ESLint\n\n');
});
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 (get, set) {
var exc = new Error('Something unexpected happened!');
var obj = _object.default.extend({
companyName: (0, _emberMetal.computed)({
get: function () {
return 'Apple, Inc.';
},
set: function (key, value) {
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'));
});
});
QUnit.module('ESLint | ember-runtime/tests/mixins/observable_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/observable_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/mixins/promise_proxy_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/promise_proxy_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/mixins/target_action_support_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/mixins/target_action_support_test.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/array.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/array.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/array/includes.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/array/includes.js should pass ESLint\n\n');
});
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);
var obj = this.newObject(expected);
var len = 3;
for (var idx = 0; idx < len; 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));
var foo = {};
equal(obj.indexOf(foo), -1, 'obj.indexOf(foo) should be < 0');
});
exports.default = suite;
});
QUnit.module('ESLint | ember-runtime/tests/suites/array/indexOf.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/array/indexOf.js should pass ESLint\n\n');
});
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);
var obj = this.newObject(expected);
var len = 3;
for (var idx = 0; idx < len; 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);
var obj = this.newObject(expected);
var len = 3;
for (var 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);
var obj = this.newObject(expected);
var len = 3;
for (var 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));
var foo = {};
equal(obj.lastIndexOf(foo), -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));
var foo = {};
equal(obj.lastIndexOf(foo, 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));
var foo = {};
equal(obj.lastIndexOf(foo, obj.length + 1), -1, 'obj.lastIndexOf(foo) should be -1');
});
exports.default = suite;
});
QUnit.module('ESLint | ember-runtime/tests/suites/array/lastIndexOf.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/array/lastIndexOf.js should pass ESLint\n\n');
});
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);
var obj = this.newObject(expected);
var len = expected.length;
for (var 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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/array/objectAt.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/array/objectAt.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/copyable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/copyable.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/copyable/copy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/copyable/copy.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/copyable/frozenCopy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/copyable/frozenCopy.js should pass ESLint\n\n');
});
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) {
if (obj.addObserver) {
var keys = Array.prototype.slice.call(arguments, 1);
var 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 (obj) {
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable.js should pass ESLint\n\n');
});
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 (i) {
return true;
});
equal(result, true, 'return value of obj.any');
});
exports.default = suite;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/any.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/any.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/compact.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/compact.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/contains.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/contains.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/every.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/every.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/filter.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/filter.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/find.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/find.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/firstObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/firstObject.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/forEach.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/forEach.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/includes.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/includes.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/invoke.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/invoke.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/is_any.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/is_any.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/lastObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/lastObject.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/map.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/map.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/mapBy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/mapBy.js should pass ESLint\n\n');
});
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, index, enumerable) {
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, enumerable) {
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/reduce.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/reduce.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/reject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/reject.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/sortBy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/sortBy.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/toArray.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/toArray.js should pass ESLint\n\n');
});
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 item = void 0,
obj = void 0,
ret = void 0;
obj = this.newObject(this.newFixture(3));
ret = obj.uniq(item);
ok(ret !== obj, 'should not be same object');
deepEqual(this.toArray(ret), this.toArray(obj), 'should be the same content');
});
exports.default = suite;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/uniq.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/uniq.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/uniqBy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/uniqBy.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/enumerable/without.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/enumerable/without.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/addObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/addObject.js should pass ESLint\n\n');
});
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 before = [];
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.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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/clear.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/clear.js should pass ESLint\n\n');
});
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');
var objectAtCalls = [];
var objectAt = obj.objectAt;
obj.objectAt = function (ix) {
objectAtCalls.push(ix);
return objectAt.call(obj, ix);
};
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
objectAtCalls.splice(0, objectAtCalls.length);
obj.insertAt(1, item);
deepEqual(objectAtCalls, [], 'objectAt is not called when only inserting items');
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/insertAt.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/insertAt.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/popObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/popObject.js should pass ESLint\n\n');
});
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 before = [];
var after = this.newFixture(1);
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.pushObject(after[0]);
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');
});
suite.test('[A,B,C,C].pushObject(A) => [A,B,C,C] + notify', function () {
var before = this.newFixture(3);
var item = before[2]; // note same object as current tail. should end up twice
var after = [before[0], before[1], before[2], item];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.pushObject(item);
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'), true, 'should have notified lastObject');
});
exports.default = suite;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/pushObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/pushObject.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/pushObjects.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/pushObjects.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/removeAt.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/removeAt.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/removeObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/removeObject.js should pass ESLint\n\n');
});
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('[A,B,C,D].replace(-1,1) => [A,B,C] + notify', function () {
var before = this.newFixture(4);
var after = [before[0], before[1], before[2]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.replace(-1, 1);
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/replace.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/replace.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/reverseObjects.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/reverseObjects.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/setObjects.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/setObjects.js should pass ESLint\n\n');
});
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 before = [];
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(), 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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/shiftObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/shiftObject.js should pass ESLint\n\n');
});
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 before = [];
var item = this.newFixture(1)[0];
var after = [item];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.unshiftObject(item);
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'), true, 'should have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
exports.default = suite;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/unshiftObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/unshiftObject.js should pass ESLint\n\n');
});
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 before = [];
var items = this.newFixture(3);
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.unshiftObjects(items);
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_array/unshiftObjects.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_array/unshiftObjects.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_enumerable.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_enumerable.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_enumerable/addObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_enumerable/addObject.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_enumerable/removeObject.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_enumerable/removeObject.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/mutable_enumerable/removeObjects.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/mutable_enumerable/removeObjects.js should pass ESLint\n\n');
});
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;
});
QUnit.module('ESLint | ember-runtime/tests/suites/suite.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/suites/suite.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/application/base_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/application/base_test.js should pass ESLint\n\n');
});
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 behavior 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);
});
});
QUnit.module('ESLint | ember-runtime/tests/system/array_proxy/arranged_content_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/array_proxy/arranged_content_test.js should pass ESLint\n\n');
});
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 behavior 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);
});
});
QUnit.module('ESLint | ember-runtime/tests/system/array_proxy/content_change_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/array_proxy/content_change_test.js should pass ESLint\n\n');
});
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 (key) {
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/array_proxy/content_update_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/array_proxy/content_update_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/array_proxy/length_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/array_proxy/length_test.js should pass ESLint\n\n');
});
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();
});
QUnit.module('ESLint | ember-runtime/tests/system/array_proxy/suite_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/array_proxy/suite_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-runtime/tests/system/array_proxy/watching_and_listening_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/array_proxy/watching_and_listening_test.js should pass ESLint\n\n');
});
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 (assert) {
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 (assert) {
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);
});
});
QUnit.module('ESLint | ember-runtime/tests/system/core_object_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/core_object_test.js should pass ESLint\n\n');
});
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);
for (var 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);
});
});
}
});
QUnit.module('ESLint | ember-runtime/tests/system/lazy_load_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/lazy_load_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/namespace/base_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/namespace/base_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/native_array/a_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/native_array/a_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/native_array/copyable_suite_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/native_array/copyable_suite_test.js should pass ESLint\n\n');
});
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();
});
QUnit.module('ESLint | ember-runtime/tests/system/native_array/suite_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/native_array/suite_test.js should pass ESLint\n\n');
});
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, set) {
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, set) {
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, set) {
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 () {
function macro(callback) {
return (0, _emberMetal.computed)(function () {
return callback.call(this);
});
}
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {
return 'FOO';
})
});
var SubClass = MyClass.extend({
foo: macro(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 () {
function macro(callback) {
return (0, _emberMetal.computed)(function () {
return callback.apply(this);
});
}
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {
return 'FOO';
})
});
var SubClass = MyClass.extend({
foo: macro(function () {
return this._super();
})
});
ok((0, _emberMetal.get)(SubClass.create(), 'foo'), 'FOO', 'super value is fetched');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/computed_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/computed_test.js should pass ESLint\n\n');
});
enifed('ember-runtime/tests/system/object/create_test', ['ember-metal', 'ember/features', 'ember-runtime/system/object'], function (_emberMetal, _features, _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');
});
if (_features.MANDATORY_SETTER) {
QUnit.test('sets up mandatory setters for watched simple properties', function () {
var MyClass = _object.default.extend({
foo: null,
bar: null,
fooDidChange: (0, _emberMetal.observer)('foo', function () {})
});
var o = MyClass.create({ foo: 'bar', bar: 'baz' });
equal(o.get('foo'), 'bar');
var descriptor = Object.getOwnPropertyDescriptor(o, 'foo');
ok(descriptor.set, 'Mandatory setter was setup');
descriptor = Object.getOwnPropertyDescriptor(o, 'bar');
ok(!descriptor.set, 'Mandatory setter was not setup');
});
}
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 (key, value) {
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 () {
var expected = 'Ember.Object.create only accepts objects.';
expectAssertion(function () {
return _object.default.create('some-string');
}, expected);
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/create_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/create_test.js should pass ESLint\n\n');
});
enifed('ember-runtime/tests/system/object/destroy_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object', 'ember/features'], function (_emberMetal, _internalTestHelpers, _object, _features) {
'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, set) {
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');
});
if (_features.MANDATORY_SETTER) {
// MANDATORY_SETTER moves value to meta.values
// a destroyed object removes meta but leaves the accessor
// that looks it up
QUnit.test('should raise an exception when modifying watched properties on a destroyed object', function () {
var obj = _object.default.extend({
fooDidChange: (0, _emberMetal.observer)('foo', function () {})
}).create({
foo: 'bar'
});
(0, _emberMetal.run)(function () {
return obj.destroy();
});
throws(function () {
return (0, _emberMetal.set)(obj, 'foo', 'baz');
}, Error, 'raises an exception');
});
}
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);
for (var 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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/destroy_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/destroy_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/detectInstance_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/detectInstance_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/detect_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/detect_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, 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 init() {
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() {
(0, _emberBabel.classCallCheck)(this, MyObject);
return (0, _emberBabel.possibleConstructorReturn)(this, _SuperObject.apply(this, arguments));
}
MyObject.prototype.method = function method() {
_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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, SubEmberObject);
calls.push('constructor');
return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject3.apply(this, arguments));
}
SubEmberObject.prototype.init = function init() {
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() {
(0, _emberBabel.classCallCheck)(this, 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() {
(0, _emberBabel.classCallCheck)(this, SubEmberObject);
calls.push('constructor');
return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject4.apply(this, arguments));
}
SubEmberObject.prototype.init = function init() {
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)');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/es-compatibility-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/es-compatibility-test.js should pass ESLint\n\n');
});
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 F = function () {
count++;
};
var obj = _object.default.extend(_evented.default).create();
obj.on('event!', F);
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 F = function () {
count++;
};
var obj = _object.default.extend(_evented.default).create();
obj.one('event!', F);
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/events_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/events_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/extend_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/extend_test.js should pass ESLint\n\n');
});
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 (get, set) {
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/observer_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/observer_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/reopenClass_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/reopenClass_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/reopen_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/reopen_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/strict-mode-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/strict-mode-test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/subclasses_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/subclasses_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object/toString_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object/toString_test.js should pass ESLint\n\n');
});
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, set) {
var Proxy = _object_proxy.default.extend({
cp: (0, _emberMetal.computed)({
get: function (key) {
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 content = { foo: { bar: 'baz' } };
var proxy = _object_proxy.default.create({ content: content });
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/object_proxy_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/object_proxy_test.js should pass ESLint\n\n');
});
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');
}
});
});
QUnit.module('ESLint | ember-runtime/tests/system/string/camelize_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/camelize_test.js should pass ESLint\n\n');
});
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');
}
});
});
QUnit.module('ESLint | ember-runtime/tests/system/string/capitalize_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/capitalize_test.js should pass ESLint\n\n');
});
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');
});
QUnit.module('ESLint | ember-runtime/tests/system/string/classify_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/classify_test.js should pass ESLint\n\n');
});
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');
}
});
});
QUnit.module('ESLint | ember-runtime/tests/system/string/dasherize_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/dasherize_test.js should pass ESLint\n\n');
});
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');
}
});
});
QUnit.module('ESLint | ember-runtime/tests/system/string/decamelize_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/decamelize_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/string/fmt_string_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/fmt_string_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-runtime/tests/system/string/loc_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/loc_test.js should pass ESLint\n\n');
});
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');
}
});
});
QUnit.module('ESLint | ember-runtime/tests/system/string/underscore_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/underscore_test.js should pass ESLint\n\n');
});
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']);
}
});
});
QUnit.module('ESLint | ember-runtime/tests/system/string/w_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/tests/system/string/w_test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-runtime/utils.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-runtime/utils.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/compat.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/compat.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/index.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/assert-input-helper-without-block.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/assert-input-helper-without-block.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/assert-reserved-named-arguments.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/assert-reserved-named-arguments.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/deprecate-render-model.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/deprecate-render-model.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/deprecate-render.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/deprecate-render.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/extract-pragma-tag.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/extract-pragma-tag.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/index.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-action-syntax.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-action-syntax.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-angle-bracket-components.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-angle-bracket-components.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-attrs-into-args.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-attrs-into-args.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-dot-component-invocation.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-dot-component-invocation.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-each-in-into-each.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-each-in-into-each.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-has-block-syntax.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-has-block-syntax.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-inline-link-to.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-inline-link-to.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-input-on-to-onEvent.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-input-on-to-onEvent.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-input-type-syntax.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-input-type-syntax.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-old-binding-syntax.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-old-binding-syntax.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-old-class-binding-syntax.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-old-class-binding-syntax.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-quoted-bindings-into-just-bindings.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-quoted-bindings-into-just-bindings.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/plugins/transform-top-level-components.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/plugins/transform-top-level-components.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/system/bootstrap.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/system/bootstrap.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/system/calculate-location-display.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/system/calculate-location-display.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/system/compile-options.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/system/compile-options.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/system/compile.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/system/compile.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-template-compiler/system/precompile.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/system/precompile.js should pass ESLint\n\n');
});
enifed('ember-template-compiler/tests/plugins/assert-input-helper-without-block-test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: assert-input-helper-without-block');
QUnit.test('Using {{#input}}{{/input}} is not valid', function () {
expect(1);
var expectedMessage = 'The {{input}} helper cannot be used in block form. (\'baz/foo-bar\' @ L1:C0) ';
expectAssertion(function () {
(0, _index.compile)('{{#input value="123"}}Completely invalid{{/input}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
});
});
QUnit.module('ESLint | ember-template-compiler/tests/plugins/assert-input-helper-without-block-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/plugins/assert-input-helper-without-block-test.js should pass ESLint\n\n');
});
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) ');
});
});
QUnit.module('ESLint | ember-template-compiler/tests/plugins/assert-reserved-named-arguments-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/plugins/assert-reserved-named-arguments-test.js should pass ESLint\n\n');
});
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);
var expectedMessage = 'Please refactor `{{render "foo-bar" coolModel}}` to a component and' + ' invoke via `{{foo-bar model=coolModel}}`. (\'baz/foo-bar\' @ L1:C0) ';
expectDeprecation(function () {
(0, _index.compile)('{{render "foo-bar" coolModel}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
});
});
QUnit.module('ESLint | ember-template-compiler/tests/plugins/deprecate-render-model-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/plugins/deprecate-render-model-test.js should pass ESLint\n\n');
});
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);
var expectedMessage = 'Please refactor `{{render "foo-bar"}}` to a component and' + ' invoke via `{{foo-bar}}`. (\'baz/foo-bar\' @ L1:C0) ';
expectDeprecation(function () {
(0, _index.compile)('{{render "foo-bar"}}', {
moduleName: 'baz/foo-bar'
});
}, expectedMessage);
});
});
QUnit.module('ESLint | ember-template-compiler/tests/plugins/deprecate-render-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/plugins/deprecate-render-test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-template-compiler/tests/plugins/transform-dot-component-invocation-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/plugins/transform-dot-component-invocation-test.js should pass ESLint\n\n');
});
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'
});
});
});
QUnit.module('ESLint | ember-template-compiler/tests/plugins/transform-inline-link-to-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/plugins/transform-inline-link-to-test.js should pass ESLint\n\n');
});
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.');
});
});
QUnit.module('ESLint | ember-template-compiler/tests/plugins/transform-input-on-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/plugins/transform-input-on-test.js should pass ESLint\n\n');
});
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}}');
});
});
QUnit.module('ESLint | ember-template-compiler/tests/plugins/transform-input-type-syntax-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/plugins/transform-input-type-syntax-test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-template-compiler/tests/system/bootstrap-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/system/bootstrap-test.js should pass ESLint\n\n');
});
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;
for (var i = 0; i < _index.defaultPlugins.length; i++) {
var plugin = _index.defaultPlugins[i];
assert.ok(plugins.indexOf(plugin) > -1, 'includes ' + plugin);
}
});
});
QUnit.module('ESLint | ember-template-compiler/tests/system/compile_options_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-template-compiler/tests/system/compile_options_test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/adapters/adapter.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/adapters/adapter.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/adapters/qunit.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/adapters/qunit.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/events.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/events.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/ext/application.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/ext/application.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/ext/rsvp.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/ext/rsvp.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/and_then.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/and_then.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/click.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/click.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/current_path.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/current_path.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/current_route_name.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/current_route_name.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/current_url.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/current_url.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/fill_in.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/fill_in.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/find.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/find.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/find_with_assert.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/find_with_assert.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/key_event.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/key_event.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/pause_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/pause_test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/trigger_event.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/trigger_event.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/visit.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/visit.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/helpers/wait.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/helpers/wait.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/index.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/initializers.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/initializers.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/setup_for_testing.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/setup_for_testing.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/support.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/support.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/test/adapter.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/test/adapter.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/test/helpers.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/test/helpers.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/test/on_inject_helpers.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/test/on_inject_helpers.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/test/pending_requests.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/test/pending_requests.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/test/promise.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/test/promise.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/test/run.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/test/run.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-testing/test/waiters.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/test/waiters.js should pass ESLint\n\n');
});
enifed('ember-testing/tests/acceptance_test', ['ember-babel', 'internal-test-helpers', 'ember-metal', 'ember-testing/test', 'ember-testing/adapters/qunit', 'ember-routing', 'ember-runtime'], function (_emberBabel, _internalTestHelpers, _emberMetal, _test, _qunit, _emberRouting, _emberRuntime) {
'use strict';
(0, _internalTestHelpers.moduleFor)('ember-testing Acceptance', function (_AutobootApplicationT) {
(0, _emberBabel.inherits)(_class, _AutobootApplicationT);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT.call(this));
_this._originalAdapter = _test.default.adapter;
_this.runTask(function () {
_this.createApplication();
_this.router.map(function () {
this.route('posts');
this.route('comments');
this.route('abort_transition');
this.route('redirect');
});
_this.indexHitCount = 0;
_this.currentRoute = 'index';
var testContext = _this;
_this.add('route:index', _emberRouting.Route.extend({
model: function () {
testContext.indexHitCount += 1;
}
}));
_this.add('route:posts', _emberRouting.Route.extend({
renderTemplate: function () {
testContext.currentRoute = 'posts';
this._super.apply(this, arguments);
}
}));
_this.addTemplate('posts', '\n \n ');
_this.add('route:comments', _emberRouting.Route.extend({
renderTemplate: function () {
testContext.currentRoute = 'comments';
this._super.apply(this, arguments);
}
}));
_this.addTemplate('comments', '{{input type="text"}}
');
_this.add('route:abort_transition', _emberRouting.Route.extend({
beforeModel: function (transition) {
transition.abort();
}
}));
_this.add('route:redirect', _emberRouting.Route.extend({
beforeModel: function () {
this.transitionTo('comments');
}
}));
_this.application.setupForTesting();
_test.default.registerAsyncHelper('slowHelper', function () {
return new _emberRuntime.RSVP.Promise(function (resolve) {
return _emberMetal.run.later(resolve, 10);
});
});
_this.application.injectTestHelpers();
});
return _this;
}
_class.prototype.teardown = function teardown() {
_test.default.adapter = this._originalAdapter;
_AutobootApplicationT.prototype.teardown.call(this);
};
_class.prototype['@test helpers can be chained with then'] = function (assert) {
var _this2 = this;
assert.expect(6);
window.visit('/posts').then(function () {
assert.equal(_this2.currentRoute, 'posts', 'Successfully visited posts route');
assert.equal(window.currentURL(), '/posts', 'posts URL is correct');
return window.click('a:contains("Comments")');
}).then(function () {
assert.equal(_this2.currentRoute, 'comments', 'visit chained with click');
return window.fillIn('.ember-text-field', 'yeah');
}).then(function () {
assert.equal(_this2.$('.ember-text-field').val(), 'yeah', 'chained with fillIn');
return window.fillIn('.ember-text-field', '#qunit-fixture', 'context working');
}).then(function () {
assert.equal(_this2.$('.ember-text-field').val(), 'context working', 'chained with fillIn');
return window.click('.does-not-exist');
}).catch(function (e) {
assert.equal(e.message, 'Element .does-not-exist not found.', 'Non-existent click exception caught');
});
};
_class.prototype['@test helpers can be chained to each other (legacy)'] = function (assert) {
var _this3 = this;
assert.expect(7);
window.visit('/posts').click('a:first', '#comments-link').fillIn('.ember-text-field', 'hello').then(function () {
assert.equal(_this3.currentRoute, 'comments', 'Successfully visited comments route');
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
assert.equal(_this3.$('.ember-text-field').val(), 'hello', 'Fillin successfully works');
window.find('.ember-text-field').one('keypress', function (e) {
assert.equal(e.keyCode, 13, 'keyevent chained with correct keyCode.');
assert.equal(e.which, 13, 'keyevent chained with correct which.');
});
}).keyEvent('.ember-text-field', 'keypress', 13).visit('/posts').then(function () {
assert.equal(_this3.currentRoute, 'posts', 'Thens can also be chained to helpers');
assert.equal(window.currentURL(), '/posts', 'URL is set correct on chained helpers');
});
};
_class.prototype['@test helpers don\'t need to be chained'] = function (assert) {
var _this4 = this;
assert.expect(5);
window.visit('/posts');
window.click('a:first', '#comments-link');
window.fillIn('.ember-text-field', 'hello');
window.andThen(function () {
assert.equal(_this4.currentRoute, 'comments', 'Successfully visited comments route');
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
assert.equal(window.find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
});
window.visit('/posts');
window.andThen(function () {
assert.equal(_this4.currentRoute, 'posts');
assert.equal(window.currentURL(), '/posts');
});
};
_class.prototype['@test Nested async helpers'] = function (assert) {
var _this5 = this;
assert.expect(5);
window.visit('/posts');
window.andThen(function () {
window.click('a:first', '#comments-link');
window.fillIn('.ember-text-field', 'hello');
});
window.andThen(function () {
assert.equal(_this5.currentRoute, 'comments', 'Successfully visited comments route');
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
assert.equal(window.find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
});
window.visit('/posts');
window.andThen(function () {
assert.equal(_this5.currentRoute, 'posts');
assert.equal(window.currentURL(), '/posts');
});
};
_class.prototype['@test Multiple nested async helpers'] = function (assert) {
var _this6 = this;
assert.expect(3);
window.visit('/posts');
window.andThen(function () {
window.click('a:first', '#comments-link');
window.fillIn('.ember-text-field', 'hello');
window.fillIn('.ember-text-field', 'goodbye');
});
window.andThen(function () {
assert.equal(window.find('.ember-text-field').val(), 'goodbye', 'Fillin successfully works');
assert.equal(_this6.currentRoute, 'comments', 'Successfully visited comments route');
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
});
};
_class.prototype['@test Helpers nested in thens'] = function (assert) {
var _this7 = this;
assert.expect(5);
window.visit('/posts').then(function () {
window.click('a:first', '#comments-link');
});
window.andThen(function () {
window.fillIn('.ember-text-field', 'hello');
});
window.andThen(function () {
assert.equal(_this7.currentRoute, 'comments', 'Successfully visited comments route');
assert.equal(window.currentURL(), '/comments', 'Comments URL is correct');
assert.equal(window.find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
});
window.visit('/posts');
window.andThen(function () {
assert.equal(_this7.currentRoute, 'posts');
assert.equal(window.currentURL(), '/posts', 'Posts URL is correct');
});
};
_class.prototype['@test Aborted transitions are not logged via Ember.Test.adapter#exception'] = function (assert) {
assert.expect(0);
_test.default.adapter = _qunit.default.create({
exception: function (error) {
assert.ok(false, 'aborted transitions are not logged');
}
});
window.visit('/abort_transition');
};
_class.prototype['@test Unhandled exceptions are logged via Ember.Test.adapter#exception'] = function (assert) {
assert.expect(2);
var asyncHandled = void 0;
_test.default.adapter = _qunit.default.create({
exception: function (error) {
assert.equal(error.message, 'Element .does-not-exist not found.', 'Exception successfully caught and passed to Ember.Test.adapter.exception');
// handle the rejection so it doesn't leak later.
asyncHandled.catch(function () {});
}
});
window.visit('/posts');
window.click('.invalid-element').catch(function (error) {
assert.equal(error.message, 'Element .invalid-element not found.', 'Exception successfully handled in the rejection handler');
});
asyncHandled = window.click('.does-not-exist');
};
_class.prototype['@test Unhandled exceptions in \'andThen\' are logged via Ember.Test.adapter#exception'] = function (assert) {
assert.expect(1);
_test.default.adapter = _qunit.default.create({
exception: function (error) {
assert.equal(error.message, 'Catch me', 'Exception successfully caught and passed to Ember.Test.adapter.exception');
}
});
window.visit('/posts');
window.andThen(function () {
throw new Error('Catch me');
});
};
_class.prototype['@test should not start routing on the root URL when visiting another'] = function (assert) {
var _this8 = this;
assert.expect(4);
window.visit('/posts');
window.andThen(function () {
assert.ok(window.find('#comments-link'), 'found comments-link');
assert.equal(_this8.currentRoute, 'posts', 'Successfully visited posts route');
assert.equal(window.currentURL(), '/posts', 'Posts URL is correct');
assert.equal(_this8.indexHitCount, 0, 'should not hit index route when visiting another route');
});
};
_class.prototype['@test only enters the index route once when visiting '] = function (assert) {
var _this9 = this;
assert.expect(1);
window.visit('/');
window.andThen(function () {
assert.equal(_this9.indexHitCount, 1, 'should hit index once when visiting /');
});
};
_class.prototype['@test test must not finish while asyncHelpers are pending'] = function (assert) {
assert.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();
this.application.testHelpers.slowHelper();
window.andThen(function () {
innerRan = true;
});
assert.equal(innerRan, false, 'should not have run yet');
assert.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();
});
}
};
_class.prototype['@test visiting a URL that causes another transition should yield the correct URL'] = function (assert) {
assert.expect(1);
window.visit('/redirect');
window.andThen(function () {
assert.equal(window.currentURL(), '/comments', 'Redirected to Comments URL');
});
};
_class.prototype['@test visiting a URL and then visiting a second URL with a transition should yield the correct URL'] = function (assert) {
assert.expect(2);
window.visit('/posts');
window.andThen(function () {
assert.equal(window.currentURL(), '/posts', 'First visited URL is correct');
});
window.visit('/redirect');
window.andThen(function () {
assert.equal(window.currentURL(), '/comments', 'Redirected to Comments URL');
});
};
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing Acceptance - teardown', function (_AutobootApplicationT2) {
(0, _emberBabel.inherits)(_class2, _AutobootApplicationT2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT2.apply(this, arguments));
}
_class2.prototype['@test that the setup/teardown happens correctly'] = function (assert) {
var _this11 = this;
assert.expect(2);
this.runTask(function () {
_this11.createApplication();
});
this.application.injectTestHelpers();
assert.ok(typeof _test.default.Promise.prototype.click === 'function');
this.runTask(function () {
_this11.application.destroy();
});
assert.equal(_test.default.Promise.prototype.click, undefined);
};
return _class2;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
QUnit.module('ESLint | ember-testing/tests/acceptance_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/acceptance_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-testing/tests/adapters/adapter_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/adapters/adapter_test.js should pass ESLint\n\n');
});
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 error = { err: 'hai' };
var originalOk = window.ok;
try {
window.ok = function (val, msg) {
originalOk(!val, 'ok is called with false');
originalOk(msg, '{err: "hai"}');
};
adapter.exception(error);
} finally {
window.ok = originalOk;
}
});
});
QUnit.module('ESLint | ember-testing/tests/adapters/qunit_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/adapters/qunit_test.js should pass ESLint\n\n');
});
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;
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);
});
});
QUnit.module('ESLint | ember-testing/tests/adapters_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/adapters_test.js should pass ESLint\n\n');
});
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);
});
});
});
QUnit.module('ESLint | ember-testing/tests/ext/rsvp_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/ext/rsvp_test.js should pass ESLint\n\n');
});
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');
});
});
QUnit.module('ESLint | ember-testing/tests/helper_registration_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/helper_registration_test.js should pass ESLint\n\n');
});
enifed('ember-testing/tests/helpers_test', ['ember-babel', 'internal-test-helpers', 'ember-routing', 'ember-runtime', 'ember-metal', 'ember-views', 'ember-glimmer', 'ember-testing/test', 'ember-testing/setup_for_testing', 'ember-testing/test/pending_requests', 'ember-testing/test/adapter', 'ember-testing/test/waiters'], function (_emberBabel, _internalTestHelpers, _emberRouting, _emberRuntime, _emberMetal, _emberViews, _emberGlimmer, _test, _setup_for_testing, _pending_requests, _adapter, _waiters) {
'use strict';
function registerHelper() {
_test.default.registerHelper('LeakyMcLeakLeak', function () {});
}
function assertHelpers(assert, 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];
assert.ok(presentInHelperContainer === expected, 'Expected \'' + helper + '\' to be present in the helper container (defaults to window).');
assert.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(assert, application, helperContainer) {
assertHelpers(assert, application, helperContainer, false);
}
var HelpersTestCase = function (_AutobootApplicationT) {
(0, _emberBabel.inherits)(HelpersTestCase, _AutobootApplicationT);
function HelpersTestCase() {
(0, _emberBabel.classCallCheck)(this, HelpersTestCase);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT.call(this));
_this._originalAdapter = (0, _adapter.getAdapter)();
return _this;
}
HelpersTestCase.prototype.teardown = function teardown() {
(0, _adapter.setAdapter)(this._originalAdapter);
(0, _emberViews.jQuery)(document).off('ajaxSend');
(0, _emberViews.jQuery)(document).off('ajaxComplete');
(0, _pending_requests.clearPendingRequests)();
if (this.application) {
this.application.removeTestHelpers();
}
_AutobootApplicationT.prototype.teardown.call(this);
};
return HelpersTestCase;
}(_internalTestHelpers.AutobootApplicationTestCase);
var HelpersApplicationTestCase = function (_HelpersTestCase) {
(0, _emberBabel.inherits)(HelpersApplicationTestCase, _HelpersTestCase);
function HelpersApplicationTestCase() {
(0, _emberBabel.classCallCheck)(this, HelpersApplicationTestCase);
var _this2 = (0, _emberBabel.possibleConstructorReturn)(this, _HelpersTestCase.call(this));
_this2.runTask(function () {
_this2.createApplication();
_this2.application.setupForTesting();
_this2.application.injectTestHelpers();
});
return _this2;
}
return HelpersApplicationTestCase;
}(HelpersTestCase);
(0, _internalTestHelpers.moduleFor)('ember-testing: Helper setup', function (_HelpersTestCase2) {
(0, _emberBabel.inherits)(_class, _HelpersTestCase2);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _HelpersTestCase2.apply(this, arguments));
}
_class.prototype['@test Ember.Application#injectTestHelpers/#removeTestHelper'] = function (assert) {
var _this4 = this;
this.runTask(function () {
_this4.createApplication();
});
assertNoHelpers(assert, this.application);
registerHelper();
this.application.injectTestHelpers();
assertHelpers(assert, this.application);
assert.ok(_test.default.Promise.prototype.LeakyMcLeakLeak, 'helper in question SHOULD be present');
this.application.removeTestHelpers();
assertNoHelpers(assert, this.application);
assert.equal(_test.default.Promise.prototype.LeakyMcLeakLeak, undefined, 'should NOT leak test promise extensions');
};
_class.prototype['@test Ember.Application#setupForTesting'] = function (assert) {
var _this5 = this;
this.runTask(function () {
_this5.createApplication();
_this5.application.setupForTesting();
});
var routerInstance = this.applicationInstance.lookup('router:main');
assert.equal(routerInstance.location, 'none');
};
_class.prototype['@test Ember.Application.setupForTesting sets the application to \'testing\''] = function (assert) {
var _this6 = this;
this.runTask(function () {
_this6.createApplication();
_this6.application.setupForTesting();
});
assert.equal(this.application.testing, true, 'Application instance is set to testing.');
};
_class.prototype['@test Ember.Application.setupForTesting leaves the system in a deferred state.'] = function (assert) {
var _this7 = this;
this.runTask(function () {
_this7.createApplication();
_this7.application.setupForTesting();
});
assert.equal(this.application._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
};
_class.prototype['@test App.reset() after Application.setupForTesting leaves the system in a deferred state.'] = function (assert) {
var _this8 = this;
this.runTask(function () {
_this8.createApplication();
_this8.application.setupForTesting();
});
assert.equal(this.application._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
this.application.reset();
assert.equal(this.application._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
};
_class.prototype['@test #setupForTesting attaches ajax listeners'] = function (assert) {
var documentEvents = _emberViews.jQuery._data(document, 'events') || {};
assert.ok(documentEvents['ajaxSend'] === undefined, 'there are no ajaxSend listers setup prior to calling injectTestHelpers');
assert.ok(documentEvents['ajaxComplete'] === undefined, 'there are no ajaxComplete listers setup prior to calling injectTestHelpers');
(0, _setup_for_testing.default)();
documentEvents = _emberViews.jQuery._data(document, 'events');
assert.equal(documentEvents['ajaxSend'].length, 1, 'calling injectTestHelpers registers an ajaxSend handler');
assert.equal(documentEvents['ajaxComplete'].length, 1, 'calling injectTestHelpers registers an ajaxComplete handler');
};
_class.prototype['@test #setupForTesting attaches ajax listeners only once'] = function (assert) {
var documentEvents = _emberViews.jQuery._data(document, 'events') || {};
assert.ok(documentEvents['ajaxSend'] === undefined, 'there are no ajaxSend listeners setup prior to calling injectTestHelpers');
assert.ok(documentEvents['ajaxComplete'] === undefined, 'there are no ajaxComplete listeners setup prior to calling injectTestHelpers');
(0, _setup_for_testing.default)();
(0, _setup_for_testing.default)();
documentEvents = _emberViews.jQuery._data(document, 'events');
assert.equal(documentEvents['ajaxSend'].length, 1, 'calling injectTestHelpers registers an ajaxSend handler');
assert.equal(documentEvents['ajaxComplete'].length, 1, 'calling injectTestHelpers registers an ajaxComplete handler');
};
_class.prototype['@test Ember.Application#injectTestHelpers calls callbacks registered with onInjectHelpers'] = function (assert) {
var _this9 = this;
var injected = 0;
_test.default.onInjectHelpers(function () {
injected++;
});
this.runTask(function () {
_this9.createApplication();
_this9.application.setupForTesting();
});
assert.equal(injected, 0, 'onInjectHelpers are not called before injectTestHelpers');
this.application.injectTestHelpers();
assert.equal(injected, 1, 'onInjectHelpers are called after injectTestHelpers');
};
_class.prototype['@test Ember.Application#injectTestHelpers adds helpers to provided object.'] = function (assert) {
var _this10 = this;
var helpers = {};
this.runTask(function () {
_this10.createApplication();
_this10.application.setupForTesting();
});
this.application.injectTestHelpers(helpers);
assertHelpers(assert, this.application, helpers);
this.application.removeTestHelpers();
assertNoHelpers(assert, this.application, helpers);
};
_class.prototype['@test Ember.Application#removeTestHelpers resets the helperContainer\'s original values'] = function (assert) {
var _this11 = this;
var helpers = { visit: 'snazzleflabber' };
this.runTask(function () {
_this11.createApplication();
_this11.application.setupForTesting();
});
this.application.injectTestHelpers(helpers);
assert.notEqual(helpers.visit, 'snazzleflabber', 'helper added to container');
this.application.removeTestHelpers();
assert.equal(helpers.visit, 'snazzleflabber', 'original value added back to container');
};
return _class;
}(HelpersTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: Helper methods', function (_HelpersApplicationTe) {
(0, _emberBabel.inherits)(_class2, _HelpersApplicationTe);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _HelpersApplicationTe.apply(this, arguments));
}
_class2.prototype['@test \'wait\' respects registerWaiters'] = function (assert) {
var _this13 = this;
assert.expect(3);
var counter = 0;
function waiter() {
return ++counter > 2;
}
var other = 0;
function otherWaiter() {
return ++other > 2;
}
this.runTask(function () {
_this13.application.advanceReadiness();
});
(0, _waiters.registerWaiter)(waiter);
(0, _waiters.registerWaiter)(otherWaiter);
var testHelpers = this.application.testHelpers;
return testHelpers.wait().then(function () {
assert.equal(waiter(), true, 'should not resolve until our waiter is ready');
(0, _waiters.unregisterWaiter)(waiter);
counter = 0;
return testHelpers.wait();
}).then(function () {
assert.equal(counter, 0, 'unregistered waiter was not checked');
assert.equal(otherWaiter(), true, 'other waiter is still registered');
}).finally(function () {
(0, _waiters.unregisterWaiter)(otherWaiter);
});
};
_class2.prototype['@test \'visit\' advances readiness.'] = function (assert) {
var _this14 = this;
assert.expect(2);
assert.equal(this.application._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
return this.application.testHelpers.visit('/').then(function () {
assert.equal(_this14.application._readinessDeferrals, 0, 'App\'s readiness was advanced by visit.');
});
};
_class2.prototype['@test \'wait\' helper can be passed a resolution value'] = function (assert) {
var _this15 = this;
assert.expect(4);
this.runTask(function () {
_this15.application.advanceReadiness();
});
var promiseObjectValue = {};
var objectValue = {};
var testHelpers = this.application.testHelpers;
return testHelpers.wait('text').then(function (val) {
assert.equal(val, 'text', 'can resolve to a string');
return testHelpers.wait(1);
}).then(function (val) {
assert.equal(val, 1, 'can resolve to an integer');
return testHelpers.wait(objectValue);
}).then(function (val) {
assert.equal(val, objectValue, 'can resolve to an object');
return testHelpers.wait(_emberRuntime.RSVP.resolve(promiseObjectValue));
}).then(function (val) {
assert.equal(val, promiseObjectValue, 'can resolve to a promise resolution value');
});
};
_class2.prototype['@test \'click\' triggers appropriate events in order'] = function (assert) {
var _this16 = this;
assert.expect(5);
this.add('component:index-wrapper', _emberGlimmer.Component.extend({
classNames: 'index-wrapper',
didInsertElement: function () {
this.$().on('mousedown focusin mouseup click', function (e) {
events.push(e.type);
});
}
}));
this.add('component:x-checkbox', _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'));
}
}));
this.addTemplate('index', '\n {{#index-wrapper}}\n {{input type="text"}}\n {{x-checkbox type="checkbox"}}\n {{textarea}}\n
\n {{/index-wrapper}}\'));\n ');
this.runTask(function () {
_this16.application.advanceReadiness();
});
var events = void 0;
var testHelpers = this.application.testHelpers;
return testHelpers.wait().then(function () {
events = [];
return testHelpers.click('.index-wrapper');
}).then(function () {
assert.deepEqual(events, ['mousedown', 'mouseup', 'click'], 'fires events in order');
}).then(function () {
events = [];
return testHelpers.click('.index-wrapper input[type=text]');
}).then(function () {
assert.deepEqual(events, ['mousedown', 'focusin', 'mouseup', 'click'], 'fires focus events on inputs');
}).then(function () {
events = [];
return testHelpers.click('.index-wrapper textarea');
}).then(function () {
assert.deepEqual(events, ['mousedown', 'focusin', 'mouseup', 'click'], 'fires focus events on textareas');
}).then(function () {
events = [];
return testHelpers.click('.index-wrapper div');
}).then(function () {
assert.deepEqual(events, ['mousedown', 'focusin', 'mouseup', 'click'], 'fires focus events on contenteditable');
}).then(function () {
events = [];
return testHelpers.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.
assert.equal(events.length, 5, 'fires click and change on checkboxes');
});
};
_class2.prototype['@test \'click\' triggers native events with simulated X/Y coordinates'] = function (assert) {
var _this17 = this;
assert.expect(15);
this.add('component:index-wrapper', _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);
}
}));
this.addTemplate('index', '\n {{#index-wrapper}}some text{{/index-wrapper}}\n ');
this.runTask(function () {
_this17.application.advanceReadiness();
});
var events = void 0;
var _application$testHelp = this.application.testHelpers,
wait = _application$testHelp.wait,
click = _application$testHelp.click;
return wait().then(function () {
events = [];
return click('.index-wrapper');
}).then(function () {
events.forEach(function (e) {
assert.ok(e instanceof window.Event, 'The event is an instance of MouseEvent');
assert.ok(typeof e.screenX === 'number', 'screenX is correct');
assert.ok(typeof e.screenY === 'number', 'screenY is correct');
assert.ok(typeof e.clientX === 'number', 'clientX is correct');
assert.ok(typeof e.clientY === 'number', 'clientY is correct');
});
});
};
_class2.prototype['@test \'triggerEvent\' with mouseenter triggers native events with simulated X/Y coordinates'] = function (assert) {
var _this18 = this;
assert.expect(5);
var evt = void 0;
this.add('component:index-wrapper', _emberGlimmer.Component.extend({
classNames: 'index-wrapper',
didInsertElement: function () {
this.element.addEventListener('mouseenter', function (e) {
return evt = e;
});
}
}));
this.addTemplate('index', '{{#index-wrapper}}some text{{/index-wrapper}}');
this.runTask(function () {
_this18.application.advanceReadiness();
});
var _application$testHelp2 = this.application.testHelpers,
wait = _application$testHelp2.wait,
triggerEvent = _application$testHelp2.triggerEvent;
return wait().then(function () {
return triggerEvent('.index-wrapper', 'mouseenter');
}).then(function () {
assert.ok(evt instanceof window.Event, 'The event is an instance of MouseEvent');
assert.ok(typeof evt.screenX === 'number', 'screenX is correct');
assert.ok(typeof evt.screenY === 'number', 'screenY is correct');
assert.ok(typeof evt.clientX === 'number', 'clientX is correct');
assert.ok(typeof evt.clientY === 'number', 'clientY is correct');
});
};
_class2.prototype['@test \'wait\' waits for outstanding timers'] = function (assert) {
var _this19 = this;
assert.expect(1);
this.runTask(function () {
_this19.application.advanceReadiness();
});
var waitDone = false;
_emberMetal.run.later(function () {
waitDone = true;
}, 20);
return this.application.testHelpers.wait().then(function () {
assert.equal(waitDone, true, 'should wait for the timer to be fired.');
});
};
_class2.prototype['@test \'wait\' respects registerWaiters with optional context'] = function (assert) {
var _this20 = this;
assert.expect(3);
var obj = {
counter: 0,
ready: function () {
return ++this.counter > 2;
}
};
var other = 0;
function otherWaiter() {
return ++other > 2;
}
this.runTask(function () {
_this20.application.advanceReadiness();
});
(0, _waiters.registerWaiter)(obj, obj.ready);
(0, _waiters.registerWaiter)(otherWaiter);
var wait = this.application.testHelpers.wait;
return wait().then(function () {
assert.equal(obj.ready(), true, 'should not resolve until our waiter is ready');
(0, _waiters.unregisterWaiter)(obj, obj.ready);
obj.counter = 0;
return wait();
}).then(function () {
assert.equal(obj.counter, 0, 'the unregistered waiter should still be at 0');
assert.equal(otherWaiter(), true, 'other waiter should still be registered');
}).finally(function () {
(0, _waiters.unregisterWaiter)(otherWaiter);
});
};
_class2.prototype['@test \'wait\' does not error if routing has not begun'] = function (assert) {
assert.expect(1);
return this.application.testHelpers.wait().then(function () {
ok(true, 'should not error without `visit`');
});
};
_class2.prototype['@test \'triggerEvent\' accepts an optional options hash without context'] = function (assert) {
var _this21 = this;
assert.expect(3);
var event = void 0;
this.add('component:index-wrapper', _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$('.input').on('keydown change', function (e) {
return event = e;
});
}
}));
this.addTemplate('index', '{{index-wrapper}}');
this.addTemplate('components/index-wrapper', '\n {{input type="text" id="scope" class="input"}}\n ');
this.runTask(function () {
_this21.application.advanceReadiness();
});
var _application$testHelp3 = this.application.testHelpers,
wait = _application$testHelp3.wait,
triggerEvent = _application$testHelp3.triggerEvent;
return wait().then(function () {
return triggerEvent('.input', 'keydown', { keyCode: 13 });
}).then(function () {
assert.equal(event.keyCode, 13, 'options were passed');
assert.equal(event.type, 'keydown', 'correct event was triggered');
assert.equal(event.target.getAttribute('id'), 'scope', 'triggered on the correct element');
});
};
_class2.prototype['@test \'triggerEvent\' can limit searching for a selector to a scope'] = function (assert) {
var _this22 = this;
assert.expect(2);
var event = void 0;
this.add('component:index-wrapper', _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$('.input').on('blur change', function (e) {
return event = e;
});
}
}));
this.addTemplate('components/index-wrapper', '\n {{input type="text" id="outside-scope" class="input"}}\n \n {{input type="text" id="inside-scope" class="input"}}\n
\n ');
this.addTemplate('index', '{{index-wrapper}}');
this.runTask(function () {
_this22.application.advanceReadiness();
});
var _application$testHelp4 = this.application.testHelpers,
wait = _application$testHelp4.wait,
triggerEvent = _application$testHelp4.triggerEvent;
return wait().then(function () {
return triggerEvent('.input', '#limited', 'blur');
}).then(function () {
assert.equal(event.type, 'blur', 'correct event was triggered');
assert.equal(event.target.getAttribute('id'), 'inside-scope', 'triggered on the correct element');
});
};
_class2.prototype['@test \'triggerEvent\' can be used to trigger arbitrary events'] = function (assert) {
var _this23 = this;
assert.expect(2);
var event = void 0;
this.add('component:index-wrapper', _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$('#foo').on('blur change', function (e) {
return event = e;
});
}
}));
this.addTemplate('components/index-wrapper', '\n {{input type="text" id="foo"}}\n ');
this.addTemplate('index', '{{index-wrapper}}');
this.runTask(function () {
_this23.application.advanceReadiness();
});
var _application$testHelp5 = this.application.testHelpers,
wait = _application$testHelp5.wait,
triggerEvent = _application$testHelp5.triggerEvent;
return wait().then(function () {
return triggerEvent('#foo', 'blur');
}).then(function () {
assert.equal(event.type, 'blur', 'correct event was triggered');
assert.equal(event.target.getAttribute('id'), 'foo', 'triggered on the correct element');
});
};
_class2.prototype['@test \'fillIn\' takes context into consideration'] = function (assert) {
var _this24 = this;
assert.expect(2);
this.addTemplate('index', '\n \n {{input type="text" id="first" class="current"}}\n
\n {{input type="text" id="second" class="current"}}\n ');
this.runTask(function () {
_this24.application.advanceReadiness();
});
var _application$testHelp6 = this.application.testHelpers,
visit = _application$testHelp6.visit,
fillIn = _application$testHelp6.fillIn,
andThen = _application$testHelp6.andThen,
find = _application$testHelp6.find;
visit('/');
fillIn('.current', '#parent', 'current value');
return andThen(function () {
assert.equal(find('#first').val(), 'current value');
assert.equal(find('#second').val(), '');
});
};
_class2.prototype['@test \'fillIn\' focuses on the element'] = function (assert) {
var _this25 = this;
assert.expect(2);
this.add('route:application', _emberRouting.Route.extend({
actions: {
wasFocused: function () {
assert.ok(true, 'focusIn event was triggered');
}
}
}));
this.addTemplate('index', '\n \n {{input type="text" id="first" focus-in="wasFocused"}}\n
\'\n ');
this.runTask(function () {
_this25.application.advanceReadiness();
});
var _application$testHelp7 = this.application.testHelpers,
visit = _application$testHelp7.visit,
fillIn = _application$testHelp7.fillIn,
andThen = _application$testHelp7.andThen,
find = _application$testHelp7.find,
wait = _application$testHelp7.wait;
visit('/');
fillIn('#first', 'current value');
andThen(function () {
assert.equal(find('#first').val(), 'current value');
});
return wait();
};
_class2.prototype['@test \'fillIn\' fires \'input\' and \'change\' events in the proper order'] = function (assert) {
var _this26 = this;
assert.expect(1);
var events = [];
this.add('controller:index', _emberRuntime.Controller.extend({
actions: {
oninputHandler: function (e) {
events.push(e.type);
},
onchangeHandler: function (e) {
events.push(e.type);
}
}
}));
this.addTemplate('index', '\n \n ');
this.runTask(function () {
_this26.application.advanceReadiness();
});
var _application$testHelp8 = this.application.testHelpers,
visit = _application$testHelp8.visit,
fillIn = _application$testHelp8.fillIn,
andThen = _application$testHelp8.andThen,
wait = _application$testHelp8.wait;
visit('/');
fillIn('#first', 'current value');
andThen(function () {
assert.deepEqual(events, ['input', 'change'], '`input` and `change` events are fired in the proper order');
});
return wait();
};
_class2.prototype['@test \'fillIn\' only sets the value in the first matched element'] = function (assert) {
var _this27 = this;
this.addTemplate('index', '\n \n \n ');
this.runTask(function () {
_this27.application.advanceReadiness();
});
var _application$testHelp9 = this.application.testHelpers,
visit = _application$testHelp9.visit,
fillIn = _application$testHelp9.fillIn,
find = _application$testHelp9.find,
andThen = _application$testHelp9.andThen,
wait = _application$testHelp9.wait;
visit('/');
fillIn('input.in-test', 'new value');
andThen(function () {
assert.equal(find('#first').val(), 'new value');
assert.equal(find('#second').val(), '');
});
return wait();
};
_class2.prototype['@test \'triggerEvent\' accepts an optional options hash and context'] = function (assert) {
var _this28 = this;
assert.expect(3);
var event = void 0;
this.add('component:index-wrapper', _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$('.input').on('keydown change', function (e) {
return event = e;
});
}
}));
this.addTemplate('components/index-wrapper', '\n {{input type="text" id="outside-scope" class="input"}}\n \n {{input type="text" id="inside-scope" class="input"}}\n
\n ');
this.addTemplate('index', '{{index-wrapper}}');
this.runTask(function () {
_this28.application.advanceReadiness();
});
var _application$testHelp10 = this.application.testHelpers,
wait = _application$testHelp10.wait,
triggerEvent = _application$testHelp10.triggerEvent;
return wait().then(function () {
return triggerEvent('.input', '#limited', 'keydown', { keyCode: 13 });
}).then(function () {
assert.equal(event.keyCode, 13, 'options were passed');
assert.equal(event.type, 'keydown', 'correct event was triggered');
assert.equal(event.target.getAttribute('id'), 'inside-scope', 'triggered on the correct element');
});
};
return _class2;
}(HelpersApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: debugging helpers', function (_HelpersApplicationTe2) {
(0, _emberBabel.inherits)(_class3, _HelpersApplicationTe2);
function _class3() {
(0, _emberBabel.classCallCheck)(this, _class3);
var _this29 = (0, _emberBabel.possibleConstructorReturn)(this, _HelpersApplicationTe2.call(this));
_this29.runTask(function () {
_this29.application.advanceReadiness();
});
return _this29;
}
_class3.prototype['@test pauseTest pauses'] = function (assert) {
assert.expect(1);
var _application$testHelp11 = this.application.testHelpers,
andThen = _application$testHelp11.andThen,
pauseTest = _application$testHelp11.pauseTest;
andThen(function () {
_test.default.adapter.asyncStart = function () {
assert.ok(true, 'Async start should be called after waiting for other helpers');
};
});
pauseTest();
};
_class3.prototype['@test resumeTest resumes paused tests'] = function (assert) {
assert.expect(1);
var _application$testHelp12 = this.application.testHelpers,
pauseTest = _application$testHelp12.pauseTest,
resumeTest = _application$testHelp12.resumeTest;
_emberMetal.run.later(function () {
return resumeTest();
}, 20);
return pauseTest().then(function () {
assert.ok(true, 'pauseTest promise was resolved');
});
};
_class3.prototype['@test resumeTest throws if nothing to resume'] = function (assert) {
var _this30 = this;
assert.expect(1);
assert.throws(function () {
_this30.application.testHelpers.resumeTest();
}, /Testing has not been paused. There is nothing to resume./);
};
return _class3;
}(HelpersApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: routing helpers', function (_HelpersTestCase3) {
(0, _emberBabel.inherits)(_class4, _HelpersTestCase3);
function _class4() {
(0, _emberBabel.classCallCheck)(this, _class4);
var _this31 = (0, _emberBabel.possibleConstructorReturn)(this, _HelpersTestCase3.call(this));
_this31.runTask(function () {
_this31.createApplication();
_this31.application.setupForTesting();
_this31.application.injectTestHelpers();
_this31.router.map(function () {
this.route('posts', { resetNamespace: true }, function () {
this.route('new');
});
});
});
_this31.runTask(function () {
_this31.application.advanceReadiness();
});
return _this31;
}
_class4.prototype['@test currentRouteName for \'/\''] = function (assert) {
assert.expect(3);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/').then(function () {
assert.equal(testHelpers.currentRouteName(), 'index', 'should equal \'index\'.');
assert.equal(testHelpers.currentPath(), 'index', 'should equal \'index\'.');
assert.equal(testHelpers.currentURL(), '/', 'should equal \'/\'.');
});
};
_class4.prototype['@test currentRouteName for \'/posts\''] = function (assert) {
assert.expect(3);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/posts').then(function () {
assert.equal(testHelpers.currentRouteName(), 'posts.index', 'should equal \'posts.index\'.');
assert.equal(testHelpers.currentPath(), 'posts.index', 'should equal \'posts.index\'.');
assert.equal(testHelpers.currentURL(), '/posts', 'should equal \'/posts\'.');
});
};
_class4.prototype['@test currentRouteName for \'/posts/new\''] = function (assert) {
assert.expect(3);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/posts/new').then(function () {
assert.equal(testHelpers.currentRouteName(), 'posts.new', 'should equal \'posts.new\'.');
assert.equal(testHelpers.currentPath(), 'posts.new', 'should equal \'posts.new\'.');
assert.equal(testHelpers.currentURL(), '/posts/new', 'should equal \'/posts/new\'.');
});
};
return _class4;
}(HelpersTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: pendingRequests', function (_HelpersApplicationTe3) {
(0, _emberBabel.inherits)(_class5, _HelpersApplicationTe3);
function _class5() {
(0, _emberBabel.classCallCheck)(this, _class5);
return (0, _emberBabel.possibleConstructorReturn)(this, _HelpersApplicationTe3.apply(this, arguments));
}
_class5.prototype['@test pendingRequests is maintained for ajaxSend and ajaxComplete events'] = function (assert) {
assert.equal((0, _pending_requests.pendingRequests)(), 0);
var xhr = { some: 'xhr' };
(0, _emberViews.jQuery)(document).trigger('ajaxSend', xhr);
assert.equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
(0, _emberViews.jQuery)(document).trigger('ajaxComplete', xhr);
assert.equal((0, _pending_requests.pendingRequests)(), 0, 'Ember.Test.pendingRequests was decremented');
};
_class5.prototype['@test pendingRequests is ignores ajaxComplete events from past setupForTesting calls'] = function (assert) {
assert.equal((0, _pending_requests.pendingRequests)(), 0);
var xhr = { some: 'xhr' };
(0, _emberViews.jQuery)(document).trigger('ajaxSend', xhr);
assert.equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
(0, _setup_for_testing.default)();
assert.equal((0, _pending_requests.pendingRequests)(), 0, 'Ember.Test.pendingRequests was reset');
var altXhr = { some: 'more xhr' };
(0, _emberViews.jQuery)(document).trigger('ajaxSend', altXhr);
assert.equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
(0, _emberViews.jQuery)(document).trigger('ajaxComplete', xhr);
assert.equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests is not impressed with your unexpected complete');
};
_class5.prototype['@test pendingRequests is reset by setupForTesting'] = function (assert) {
(0, _pending_requests.incrementPendingRequests)();
(0, _setup_for_testing.default)();
assert.equal((0, _pending_requests.pendingRequests)(), 0, 'pendingRequests is reset');
};
return _class5;
}(HelpersApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: async router', function (_HelpersTestCase4) {
(0, _emberBabel.inherits)(_class6, _HelpersTestCase4);
function _class6() {
(0, _emberBabel.classCallCheck)(this, _class6);
var _this33 = (0, _emberBabel.possibleConstructorReturn)(this, _HelpersTestCase4.call(this));
_this33.runTask(function () {
_this33.createApplication();
_this33.router.map(function () {
this.route('user', { resetNamespace: true }, function () {
this.route('profile');
this.route('edit');
});
});
// Emulate a long-running unscheduled async operation.
var resolveLater = function () {
return new _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.
*/
_emberMetal.run.later(resolve, { firstName: 'Tom' }, 20);
});
};
_this33.add('route:user', _emberRouting.Route.extend({
model: function () {
return resolveLater();
}
}));
_this33.add('route:user.profile', _emberRouting.Route.extend({
beforeModel: function () {
var _this34 = this;
return resolveLater().then(function () {
return _this34.transitionTo('user.edit');
});
}
}));
_this33.application.setupForTesting();
});
_this33.application.injectTestHelpers();
_this33.runTask(function () {
_this33.application.advanceReadiness();
});
return _this33;
}
_class6.prototype['@test currentRouteName for \'/user\''] = function (assert) {
var _this35 = this;
assert.expect(4);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/user').then(function () {
assert.equal(testHelpers.currentRouteName(), 'user.index', 'should equal \'user.index\'.');
assert.equal(testHelpers.currentPath(), 'user.index', 'should equal \'user.index\'.');
assert.equal(testHelpers.currentURL(), '/user', 'should equal \'/user\'.');
var userRoute = _this35.applicationInstance.lookup('route:user');
assert.equal(userRoute.get('controller.model.firstName'), 'Tom', 'should equal \'Tom\'.');
});
};
_class6.prototype['@test currentRouteName for \'/user/profile\''] = function (assert) {
var _this36 = this;
assert.expect(4);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/user/profile').then(function () {
assert.equal(testHelpers.currentRouteName(), 'user.edit', 'should equal \'user.edit\'.');
assert.equal(testHelpers.currentPath(), 'user.edit', 'should equal \'user.edit\'.');
assert.equal(testHelpers.currentURL(), '/user/edit', 'should equal \'/user/edit\'.');
var userRoute = _this36.applicationInstance.lookup('route:user');
assert.equal(userRoute.get('controller.model.firstName'), 'Tom', 'should equal \'Tom\'.');
});
};
return _class6;
}(HelpersTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: can override built-in helpers', function (_HelpersTestCase5) {
(0, _emberBabel.inherits)(_class7, _HelpersTestCase5);
function _class7() {
(0, _emberBabel.classCallCheck)(this, _class7);
var _this37 = (0, _emberBabel.possibleConstructorReturn)(this, _HelpersTestCase5.call(this));
_this37.runTask(function () {
_this37.createApplication();
_this37.application.setupForTesting();
});
_this37._originalVisitHelper = _test.default._helpers.visit;
_this37._originalFindHelper = _test.default._helpers.find;
return _this37;
}
_class7.prototype.teardown = function teardown() {
_test.default._helpers.visit = this._originalVisitHelper;
_test.default._helpers.find = this._originalFindHelper;
_HelpersTestCase5.prototype.teardown.call(this);
};
_class7.prototype['@test can override visit helper'] = function (assert) {
assert.expect(1);
_test.default.registerHelper('visit', function () {
assert.ok(true, 'custom visit helper was called');
});
this.application.injectTestHelpers();
return this.application.testHelpers.visit();
};
_class7.prototype['@test can override find helper'] = function (assert) {
assert.expect(1);
_test.default.registerHelper('find', function () {
assert.ok(true, 'custom find helper was called');
return ['not empty array'];
});
this.application.injectTestHelpers();
return this.application.testHelpers.findWithAssert('.who-cares');
};
return _class7;
}(HelpersTestCase));
});
QUnit.module('ESLint | ember-testing/tests/helpers_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/helpers_test.js should pass ESLint\n\n');
});
enifed('ember-testing/tests/integration_test', ['ember-babel', 'internal-test-helpers', 'ember-testing/test', 'ember-runtime', 'ember-routing'], function (_emberBabel, _internalTestHelpers, _test, _emberRuntime, _emberRouting) {
'use strict';
(0, _internalTestHelpers.moduleFor)('ember-testing Integration tests of acceptance', function (_AutobootApplicationT) {
(0, _emberBabel.inherits)(_class, _AutobootApplicationT);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT.call(this));
_this.modelContent = [];
_this._originalAdapter = _test.default.adapter;
_this.runTask(function () {
_this.createApplication();
_this.addTemplate('people', '\n \n {{#each model as |person|}}\n
{{person.firstName}}
\n {{/each}}\n
\n ');
_this.router.map(function () {
this.route('people', { path: '/' });
});
_this.add('route:people', _emberRouting.Route.extend({
model: function () {
return _this.modelContent;
}
}));
_this.application.setupForTesting();
});
_this.runTask(function () {
_this.application.reset();
});
_this.application.injectTestHelpers();
return _this;
}
_class.prototype.teardown = function teardown() {
_AutobootApplicationT.prototype.teardown.call(this);
_test.default.adapter = this._originalAdapter;
};
_class.prototype['@test template is bound to empty array of people'] = function (assert) {
var _this2 = this;
this.runTask(function () {
return _this2.application.advanceReadiness();
});
window.visit('/').then(function () {
var rows = window.find('.name').length;
assert.equal(rows, 0, 'successfully stubbed an empty array of people');
});
};
_class.prototype['@test template is bound to array of 2 people'] = function (assert) {
var _this3 = this;
this.modelContent = (0, _emberRuntime.A)([]);
this.modelContent.pushObject({ firstName: 'x' });
this.modelContent.pushObject({ firstName: 'y' });
this.runTask(function () {
return _this3.application.advanceReadiness();
});
window.visit('/').then(function () {
var rows = window.find('.name').length;
assert.equal(rows, 2, 'successfully stubbed a non empty array of people');
});
};
_class.prototype['@test \'visit\' can be called without advanceReadiness.'] = function (assert) {
window.visit('/').then(function () {
var rows = window.find('.name').length;
assert.equal(rows, 0, 'stubbed an empty array of people without calling advanceReadiness.');
});
};
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
QUnit.module('ESLint | ember-testing/tests/integration_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/integration_test.js should pass ESLint\n\n');
});
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);
});
});
});
QUnit.module('ESLint | ember-testing/tests/reexports_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/reexports_test.js should pass ESLint\n\n');
});
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;
}
}
});
});
QUnit.module('ESLint | ember-testing/tests/simple_setup.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/simple_setup.js should pass ESLint\n\n');
});
enifed('ember-testing/tests/test/waiters-test', ['ember-babel', 'ember-testing/test/waiters'], function (_emberBabel, _waiters) {
'use strict';
var Waiters = function () {
function Waiters() {
(0, _emberBabel.classCallCheck)(this, Waiters);
this._waiters = [];
}
Waiters.prototype.add = function add() {
this._waiters.push([].concat(Array.prototype.slice.call(arguments)));
};
Waiters.prototype.register = function register() {
this.forEach(function () {
_waiters.registerWaiter.apply(undefined, arguments);
});
};
Waiters.prototype.unregister = function unregister() {
this.forEach(function () {
_waiters.unregisterWaiter.apply(undefined, arguments);
});
};
Waiters.prototype.forEach = function forEach(callback) {
for (var i = 0; i < this._waiters.length; i++) {
var args = this._waiters[i];
callback.apply(undefined, args);
}
};
Waiters.prototype.check = function check() {
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);
var obj = { foo: true };
this.waiters.add(obj, function () {
assert.ok(this.foo, 'has proper `this` context');
return true;
});
this.waiters.add(function () {
assert.ok(true, 'is called');
return true;
});
this.waiters.check();
});
QUnit.test('unregistering a waiter', function (assert) {
assert.expect(2);
var obj = { foo: true };
this.waiters.add(obj, function () {
assert.ok(true, 'precond - waiter with context is registered');
return true;
});
this.waiters.add(function () {
assert.ok(true, 'precond - waiter without context is registered');
return true;
});
this.waiters.check();
this.waiters.unregister();
(0, _waiters.checkWaiters)();
});
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.module('ESLint | ember-testing/tests/test/waiters-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-testing/tests/test/waiters-test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-utils.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils.js should pass ESLint\n\n');
});
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 };
var src1 = { a: 2, b: 2 };
var src2 = { a: 3 };
(0, _emberUtils.assignPolyfill)(trgt, src1, src2);
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');
});
});
QUnit.module('ESLint | ember-utils/tests/assign_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/assign_test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-utils/tests/can_invoke_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/can_invoke_test.js should pass ESLint\n\n');
});
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');
});
}
});
QUnit.module('ESLint | ember-utils/tests/checkHasSuper_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/checkHasSuper_test.js should pass ESLint\n\n');
});
enifed('ember-utils/tests/generate_guid_test', ['ember-utils'], function (_emberUtils) {
'use strict';
QUnit.module('Ember.generateGuid');
QUnit.test('Prefix', function () {
var a = {};
ok((0, _emberUtils.generateGuid)(a, 'tyrell').indexOf('tyrell') > -1, 'guid can be prefixed');
});
});
QUnit.module('ESLint | ember-utils/tests/generate_guid_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/generate_guid_test.js should pass ESLint\n\n');
});
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) {
var type = typeof obj;
ok(isNaN(parseInt((0, _emberUtils.guidFor)(obj), 0)), 'guids for ' + type + 'don\'t parse to numbers');
}
QUnit.test('Object', function () {
var a = {};
var b = {};
sameGuid(a, a, 'same object always yields same guid');
diffGuid(a, b, 'different objects yield different guids');
nanGuid(a);
});
QUnit.test('strings', function () {
var a = 'string A';
var aprime = 'string A';
var b = 'String B';
sameGuid(a, a, 'same string always yields same guid');
sameGuid(a, aprime, 'identical strings always yield the same guid');
diffGuid(a, b, 'different strings yield different guids');
nanGuid(a);
});
QUnit.test('numbers', function () {
var a = 23;
var aprime = 23;
var b = 34;
sameGuid(a, a, 'same numbers always yields same guid');
sameGuid(a, aprime, 'identical numbers always yield the same guid');
diffGuid(a, b, 'different numbers yield different guids');
nanGuid(a);
});
QUnit.test('numbers', function () {
var a = true;
var aprime = true;
var b = false;
sameGuid(a, a, 'same booleans always yields same guid');
sameGuid(a, aprime, '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 aprime = 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, aprime, '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'];
var aprime = ['a', 'b', 'c'];
var b = ['1', '2', '3'];
sameGuid(a, a, 'same instance always yields same guid');
diffGuid(a, aprime, 'identical arrays always yield the same guid');
diffGuid(a, b, 'different arrays yield different guids');
nanGuid(a);
});
});
QUnit.module('ESLint | ember-utils/tests/guid_for_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/guid_for_test.js should pass ESLint\n\n');
});
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 () {
if (HAS_NATIVE_SYMBOL) {
var symbol = Symbol('test');
equal((0, _emberUtils.inspect)(symbol), 'Symbol(test)');
} else {
expect(0);
}
});
});
QUnit.module('ESLint | ember-utils/tests/inspect_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/inspect_test.js should pass ESLint\n\n');
});
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)({}), [{}]);
});
});
QUnit.module('ESLint | ember-utils/tests/make_array_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/make_array_test.js should pass ESLint\n\n');
});
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 () {
var obj = {
toString: function () {
return 'bob';
}
};
strictEqual((0, _emberUtils.toString)(obj), '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);
var arr = [obj, 2];
strictEqual((0, _emberUtils.toString)(arr), {}.toString() + ',2');
});
});
QUnit.module('ESLint | ember-utils/tests/to-string-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/to-string-test.js should pass ESLint\n\n');
});
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);
});
});
QUnit.module('ESLint | ember-utils/tests/try_invoke_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-utils/tests/try_invoke_test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/compat/attrs.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/compat/attrs.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/compat/fallback-view-registry.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/compat/fallback-view-registry.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/component_lookup.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/component_lookup.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/index.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/mixins/action_support.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/mixins/action_support.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/mixins/child_views_support.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/mixins/child_views_support.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/mixins/class_names_support.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/mixins/class_names_support.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/mixins/text_support.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/mixins/text_support.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/mixins/view_state_support.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/mixins/view_state_support.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/mixins/view_support.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/mixins/view_support.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/system/action_manager.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/system/action_manager.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/system/event_dispatcher.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/system/event_dispatcher.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/system/ext.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/system/ext.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/system/jquery.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/system/jquery.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/system/lookup_partial.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/system/lookup_partial.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/system/utils.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/system/utils.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/utils/lookup-component.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/utils/lookup-component.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/views/core_view.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/views/core_view.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/views/states.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/views/states.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/views/states/default.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/views/states/default.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/views/states/destroying.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/views/states/destroying.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/views/states/has_element.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/views/states/has_element.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/views/states/in_dom.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/views/states/in_dom.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember-views/views/states/pre_render.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember-views/views/states/pre_render.js should pass ESLint\n\n');
});
QUnit.module('ESLint | ember/index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/index.js should pass ESLint\n\n');
});
enifed('ember/tests/application_lifecycle_test', ['ember-babel', 'internal-test-helpers', 'ember-application', 'ember-routing', 'ember-glimmer'], function (_emberBabel, _internalTestHelpers, _emberApplication, _emberRouting, _emberGlimmer) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Application Lifecycle - route hooks', function (_AutobootApplicationT) {
(0, _emberBabel.inherits)(_class, _AutobootApplicationT);
_class.prototype.createApplication = function createApplication() {
var _AutobootApplicationT2;
var application = (_AutobootApplicationT2 = _AutobootApplicationT.prototype.createApplication).call.apply(_AutobootApplicationT2, [this].concat(Array.prototype.slice.call(arguments)));
this.add('router:main', _emberRouting.Router.extend({
location: 'none'
}));
return application;
};
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT.call(this));
var menuItem = _this.menuItem = {};
_this.runTask(function () {
_this.createApplication();
var SettingRoute = _emberRouting.Route.extend({
setupController: function () {
this.controller.set('selectedMenuItem', menuItem);
},
deactivate: function () {
this.controller.set('selectedMenuItem', null);
}
});
_this.add('route:index', SettingRoute);
_this.add('route:application', SettingRoute);
});
return _this;
}
_class.prototype['@test Resetting the application allows controller properties to be set when a route deactivates'] = function (assert) {
var indexController = this.indexController,
applicationController = this.applicationController;
assert.equal(indexController.get('selectedMenuItem'), this.menuItem);
assert.equal(applicationController.get('selectedMenuItem'), this.menuItem);
this.application.reset();
assert.equal(indexController.get('selectedMenuItem'), null);
assert.equal(applicationController.get('selectedMenuItem'), null);
};
_class.prototype['@test Destroying the application resets the router before the appInstance is destroyed'] = function (assert) {
var _this2 = this;
var indexController = this.indexController,
applicationController = this.applicationController;
assert.equal(indexController.get('selectedMenuItem'), this.menuItem);
assert.equal(applicationController.get('selectedMenuItem'), this.menuItem);
this.runTask(function () {
_this2.application.destroy();
});
assert.equal(indexController.get('selectedMenuItem'), null);
assert.equal(applicationController.get('selectedMenuItem'), null);
};
(0, _emberBabel.createClass)(_class, [{
key: 'indexController',
get: function () {
return this.applicationInstance.lookup('controller:index');
}
}, {
key: 'applicationController',
get: function () {
return this.applicationInstance.lookup('controller:application');
}
}]);
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Application Lifecycle', function (_AutobootApplicationT3) {
(0, _emberBabel.inherits)(_class2, _AutobootApplicationT3);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT3.apply(this, arguments));
}
_class2.prototype.createApplication = function createApplication() {
var _AutobootApplicationT4;
var application = (_AutobootApplicationT4 = _AutobootApplicationT3.prototype.createApplication).call.apply(_AutobootApplicationT4, [this].concat(Array.prototype.slice.call(arguments)));
this.add('router:main', _emberRouting.Router.extend({
location: 'none'
}));
return application;
};
_class2.prototype['@test Destroying a route after the router does create an undestroyed \'toplevelView\''] = function (assert) {
var _this4 = this;
this.runTask(function () {
_this4.createApplication();
_this4.addTemplate('index', 'Index!');
_this4.addTemplate('application', 'Application! {{outlet}}');
});
var router = this.applicationInstance.lookup('router:main');
var route = this.applicationInstance.lookup('route:index');
this.runTask(function () {
return router.destroy();
});
equal(router._toplevelView, null, 'the toplevelView was cleared');
this.runTask(function () {
return route.destroy();
});
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
this.runTask(function () {
return _this4.application.destroy();
});
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
};
_class2.prototype['@test initializers can augment an applications customEvents hash'] = function (assert) {
var _this5 = this;
assert.expect(1);
var MyApplication = _emberApplication.Application.extend();
MyApplication.initializer({
name: 'customize-things',
initialize: function (application) {
application.customEvents = {
wowza: 'wowza'
};
}
});
this.runTask(function () {
_this5.createApplication({}, MyApplication);
_this5.add('component:foo-bar', _emberGlimmer.Component.extend({
wowza: function () {
assert.ok(true, 'fired the event!');
}
}));
_this5.addTemplate('application', '{{foo-bar}}');
_this5.addTemplate('components/foo-bar', '
');
});
this.$('#wowza-thingy').trigger('wowza');
};
_class2.prototype['@test instanceInitializers can augment an the customEvents hash'] = function (assert) {
var _this6 = this;
assert.expect(1);
var MyApplication = _emberApplication.Application.extend();
MyApplication.instanceInitializer({
name: 'customize-things',
initialize: function (application) {
application.customEvents = {
herky: 'jerky'
};
}
});
this.runTask(function () {
_this6.createApplication({}, MyApplication);
_this6.add('component:foo-bar', _emberGlimmer.Component.extend({
jerky: function () {
assert.ok(true, 'fired the event!');
}
}));
_this6.addTemplate('application', '{{foo-bar}}');
_this6.addTemplate('components/foo-bar', '
');
});
this.$('#herky-thingy').trigger('herky');
};
return _class2;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
QUnit.module('ESLint | ember/tests/application_lifecycle_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/application_lifecycle_test.js should pass ESLint\n\n');
});
enifed('ember/tests/component_context_test', ['ember-babel', 'ember-runtime', 'ember-glimmer', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberGlimmer, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Application Lifecycle - Component Context', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Components with a block should have the proper content when a template is provided'] = function testComponentsWithABlockShouldHaveTheProperContentWhenATemplateIsProvided(assert) {
var _this2 = this;
this.addTemplate('application', '\n \n {{#my-component}}{{text}}{{/my-component}}\n
\n ');
this.add('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
this.addComponent('my-component', {
ComponentClass: _emberGlimmer.Component.extend({
text: 'inner'
}),
template: '{{text}}-{{yield}}'
});
this.visit('/').then(function () {
var text = _this2.$('#wrapper').text().trim();
assert.equal(text, 'inner-outer', 'The component is composed correctly');
});
};
_class.prototype['@test Components with a block should yield the proper content without a template provided'] = function testComponentsWithABlockShouldYieldTheProperContentWithoutATemplateProvided(assert) {
var _this3 = this;
this.addTemplate('application', '\n \n {{#my-component}}{{text}}{{/my-component}}\n
\n ');
this.add('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
this.addComponent('my-component', {
ComponentClass: _emberGlimmer.Component.extend({
text: 'inner'
})
});
this.visit('/').then(function () {
var text = _this3.$('#wrapper').text().trim();
assert.equal(text, 'outer', 'The component is composed correctly');
});
};
_class.prototype['@test Components without a block should have the proper content when a template is provided'] = function testComponentsWithoutABlockShouldHaveTheProperContentWhenATemplateIsProvided(assert) {
var _this4 = this;
this.addTemplate('application', '\n {{my-component}}
\n ');
this.add('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
this.addComponent('my-component', {
ComponentClass: _emberGlimmer.Component.extend({
text: 'inner'
}),
template: '{{text}}'
});
this.visit('/').then(function () {
var text = _this4.$('#wrapper').text().trim();
assert.equal(text, 'inner', 'The component is composed correctly');
});
};
_class.prototype['@test Components without a block should have the proper content'] = function testComponentsWithoutABlockShouldHaveTheProperContent(assert) {
var _this5 = this;
this.addTemplate('application', '\n {{my-component}}
\n ');
this.add('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
this.addComponent('my-component', {
ComponentClass: _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$().html('Some text inserted by jQuery');
}
})
});
this.visit('/').then(function () {
var text = _this5.$('#wrapper').text().trim();
assert.equal(text, 'Some text inserted by jQuery', 'The component is composed correctly');
});
};
_class.prototype['@test properties of a component without a template should not collide with internal structures [DEPRECATED]'] = function testPropertiesOfAComponentWithoutATemplateShouldNotCollideWithInternalStructuresDEPRECATED(assert) {
var _this6 = this;
this.addTemplate('application', '\n {{my-component data=foo}}
');
this.add('controller:application', _emberRuntime.Controller.extend({
'text': 'outer',
'foo': 'Some text inserted by jQuery'
}));
this.addComponent('my-component', {
ComponentClass: _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$().html(this.get('data'));
}
})
});
this.visit('/').then(function () {
var text = _this6.$('#wrapper').text().trim();
assert.equal(text, 'Some text inserted by jQuery', 'The component is composed correctly');
});
};
_class.prototype['@test attrs property of a component without a template should not collide with internal structures'] = function testAttrsPropertyOfAComponentWithoutATemplateShouldNotCollideWithInternalStructures(assert) {
var _this7 = this;
this.addTemplate('application', '\n {{my-component attrs=foo}}
\n ');
this.add('controller:application', _emberRuntime.Controller.extend({
'text': 'outer',
'foo': 'Some text inserted by jQuery'
}));
this.addComponent('my-component', {
ComponentClass: _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'));
}
})
});
this.visit('/').then(function () {
var text = _this7.$('#wrapper').text().trim();
assert.equal(text, 'Some text inserted by jQuery', 'The component is composed correctly');
});
};
_class.prototype['@test Components trigger actions in the parents context when called from within a block'] = function testComponentsTriggerActionsInTheParentsContextWhenCalledFromWithinABlock(assert) {
var _this8 = this;
this.addTemplate('application', '\n \n {{#my-component}}\n
Fizzbuzz \n {{/my-component}}\n
\n ');
this.add('controller:application', _emberRuntime.Controller.extend({
actions: {
fizzbuzz: function () {
ok(true, 'action triggered on parent');
}
}
}));
this.addComponent('my-component', { ComponentClass: _emberGlimmer.Component.extend({}) });
this.visit('/').then(function () {
_this8.$('#fizzbuzz', '#wrapper').click();
});
};
_class.prototype['@test Components trigger actions in the components context when called from within its template'] = function testComponentsTriggerActionsInTheComponentsContextWhenCalledFromWithinItsTemplate(assert) {
var _this9 = this;
this.addTemplate('application', '\n {{#my-component}}{{text}}{{/my-component}}
\n ');
this.add('controller:application', _emberRuntime.Controller.extend({
actions: {
fizzbuzz: function () {
ok(false, 'action on the wrong context');
}
}
}));
this.addComponent('my-component', {
ComponentClass: _emberGlimmer.Component.extend({
actions: {
fizzbuzz: function () {
ok(true, 'action triggered on component');
}
}
}),
template: 'Fizzbuzz '
});
this.visit('/').then(function () {
_this9.$('#fizzbuzz', '#wrapper').click();
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
QUnit.module('ESLint | ember/tests/component_context_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/component_context_test.js should pass ESLint\n\n');
});
enifed('ember/tests/component_registration_test', ['ember-babel', 'ember-runtime', 'ember-glimmer', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberGlimmer, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Application Lifecycle - Component Registration', function (_AutobootApplicationT) {
(0, _emberBabel.inherits)(_class, _AutobootApplicationT);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT.apply(this, arguments));
}
_class.prototype['@test The helper becomes the body of the component'] = function testTheHelperBecomesTheBodyOfTheComponent(assert) {
var _this2 = this;
this.runTask(function () {
_this2.createApplication();
_this2.addTemplate('components/expand-it', 'hello {{yield}}
');
_this2.addTemplate('application', 'Hello world {{#expand-it}}world{{/expand-it}}');
});
var text = this.$('div.ember-view > div.ember-view').text().trim();
assert.equal(text, 'hello world', 'The component is composed correctly');
};
_class.prototype['@test If a component is registered, it is used'] = function testIfAComponentIsRegisteredItIsUsed(assert) {
var _this3 = this;
this.runTask(function () {
_this3.createApplication();
_this3.addTemplate('components/expand-it', 'hello {{yield}}
');
_this3.addTemplate('application', 'Hello world {{#expand-it}}world{{/expand-it}}');
_this3.applicationInstance.register('component:expand-it', _emberGlimmer.Component.extend({
classNames: 'testing123'
}));
});
var text = this.$('div.testing123').text().trim();
assert.equal(text, 'hello world', 'The component is composed correctly');
};
_class.prototype['@test Late-registered components can be rendered with custom `layout` property'] = function testLateRegisteredComponentsCanBeRenderedWithCustomLayoutProperty(assert) {
var _this4 = this;
this.runTask(function () {
_this4.createApplication();
_this4.addTemplate('application', 'there goes {{my-hero}}
');
_this4.applicationInstance.register('component:my-hero', _emberGlimmer.Component.extend({
classNames: 'testing123',
layout: _this4.compile('watch him as he GOES')
}));
});
var text = this.$('#wrapper').text().trim();
assert.equal(text, 'there goes watch him as he GOES', 'The component is composed correctly');
};
_class.prototype['@test Late-registered components can be rendered with template registered on the container'] = function testLateRegisteredComponentsCanBeRenderedWithTemplateRegisteredOnTheContainer(assert) {
var _this5 = this;
this.runTask(function () {
_this5.createApplication();
_this5.addTemplate('application', 'hello world {{sally-rutherford}}-{{#sally-rutherford}}!!!{{/sally-rutherford}}
');
_this5.applicationInstance.register('template:components/sally-rutherford', _this5.compile('funkytowny{{yield}}'));
_this5.applicationInstance.register('component:sally-rutherford', _emberGlimmer.Component);
});
var text = this.$('#wrapper').text().trim();
assert.equal(text, 'hello world funkytowny-funkytowny!!!', 'The component is composed correctly');
};
_class.prototype['@test Late-registered components can be rendered with ONLY the template registered on the container'] = function testLateRegisteredComponentsCanBeRenderedWithONLYTheTemplateRegisteredOnTheContainer(assert) {
var _this6 = this;
this.runTask(function () {
_this6.createApplication();
_this6.addTemplate('application', 'hello world {{borf-snorlax}}-{{#borf-snorlax}}!!!{{/borf-snorlax}}
');
_this6.applicationInstance.register('template:components/borf-snorlax', _this6.compile('goodfreakingTIMES{{yield}}'));
});
var text = this.$('#wrapper').text().trim();
assert.equal(text, 'hello world goodfreakingTIMES-goodfreakingTIMES!!!', 'The component is composed correctly');
};
_class.prototype['@test Assigning layoutName to a component should setup the template as a layout'] = function testAssigningLayoutNameToAComponentShouldSetupTheTemplateAsALayout(assert) {
var _this7 = this;
assert.expect(1);
this.runTask(function () {
_this7.createApplication();
_this7.addTemplate('application', '{{#my-component}}{{text}}{{/my-component}}
');
_this7.addTemplate('foo-bar-baz', '{{text}}-{{yield}}');
_this7.applicationInstance.register('controller:application', _emberRuntime.Controller.extend({
text: 'outer'
}));
_this7.applicationInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner',
layoutName: 'foo-bar-baz'
}));
});
var text = this.$('#wrapper').text().trim();
assert.equal(text, 'inner-outer', 'The component is composed correctly');
};
_class.prototype['@test Assigning layoutName and layout to a component should use the `layout` value'] = function testAssigningLayoutNameAndLayoutToAComponentShouldUseTheLayoutValue(assert) {
var _this8 = this;
assert.expect(1);
this.runTask(function () {
_this8.createApplication();
_this8.addTemplate('application', '{{#my-component}}{{text}}{{/my-component}}
');
_this8.addTemplate('foo-bar-baz', 'No way!');
_this8.applicationInstance.register('controller:application', _emberRuntime.Controller.extend({
text: 'outer'
}));
_this8.applicationInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner',
layoutName: 'foo-bar-baz',
layout: _this8.compile('{{text}}-{{yield}}')
}));
});
var text = this.$('#wrapper').text().trim();
assert.equal(text, 'inner-outer', 'The component is composed correctly');
};
_class.prototype['@test Assigning defaultLayout to a component should set it up as a layout if no layout was found [DEPRECATED]'] = function testAssigningDefaultLayoutToAComponentShouldSetItUpAsALayoutIfNoLayoutWasFoundDEPRECATED(assert) {
var _this9 = this;
assert.expect(2);
expectDeprecation(function () {
_this9.runTask(function () {
_this9.createApplication();
_this9.addTemplate('application', '{{#my-component}}{{text}}{{/my-component}}
');
_this9.applicationInstance.register('controller:application', _emberRuntime.Controller.extend({
text: 'outer'
}));
_this9.applicationInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner',
defaultLayout: _this9.compile('{{text}}-{{yield}}')
}));
});
});
var text = this.$('#wrapper').text().trim();
assert.equal(text, 'inner-outer', 'The component is composed correctly');
};
_class.prototype['@test Assigning defaultLayout to a component should set it up as a layout if layout was found [DEPRECATED]'] = function testAssigningDefaultLayoutToAComponentShouldSetItUpAsALayoutIfLayoutWasFoundDEPRECATED(assert) {
var _this10 = this;
assert.expect(2);
expectDeprecation(function () {
_this10.runTask(function () {
_this10.createApplication();
_this10.addTemplate('application', '{{#my-component}}{{text}}{{/my-component}}
');
_this10.addTemplate('components/my-component', '{{text}}-{{yield}}');
_this10.applicationInstance.register('controller:application', _emberRuntime.Controller.extend({
text: 'outer'
}));
_this10.applicationInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner',
defaultLayout: _this10.compile('should not see this!')
}));
});
}, /Specifying `defaultLayout` to .+ is deprecated\./);
var text = this.$('#wrapper').text().trim();
assert.equal(text, 'inner-outer', 'The component is composed correctly');
};
_class.prototype['@test Using name of component that does not exist'] = function testUsingNameOfComponentThatDoesNotExist() {
var _this11 = this;
expectAssertion(function () {
_this11.runTask(function () {
_this11.createApplication();
_this11.addTemplate('application', '{{#no-good}} {{/no-good}}
');
});
}, /.* named "no-good" .*/);
};
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
QUnit.module('ESLint | ember/tests/component_registration_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/component_registration_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Actions inside an outlet go to the associated controller'] = function testActionsInsideAnOutletGoToTheAssociatedController(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));
});
QUnit.module('ESLint | ember/tests/controller_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/controller_test.js should pass ESLint\n\n');
});
enifed('ember/tests/error_handler_test', ['ember', 'ember-metal'], function (_ember, _emberMetal) {
'use strict';
var ONERROR = _ember.default.onerror;
var ADAPTER = _ember.default.Test && _ember.default.Test.adapter;
var TESTING = _ember.default.testing;
QUnit.module('error_handler', {
teardown: function () {
_ember.default.onerror = ONERROR;
_ember.default.testing = TESTING;
if (_ember.default.Test) {
_ember.default.Test.adapter = ADAPTER;
}
}
});
function runThatThrows(message) {
return (0, _emberMetal.run)(function () {
throw new Error(message);
});
}
test('by default there is no onerror', function (assert) {
_ember.default.onerror = undefined;
assert.throws(runThatThrows, Error);
assert.equal(_ember.default.onerror, undefined);
});
test('when Ember.onerror is registered', function (assert) {
assert.expect(2);
_ember.default.onerror = function (error) {
assert.ok(true, 'onerror called');
throw error;
};
assert.throws(runThatThrows, Error);
// Ember.onerror = ONERROR;
});
if (true) {
test('when Ember.Test.adapter is registered', function (assert) {
assert.expect(2);
_ember.default.Test.adapter = {
exception: function (error) {
assert.ok(true, 'adapter called');
throw error;
}
};
assert.throws(runThatThrows, Error);
});
test('when both Ember.onerror Ember.Test.adapter are registered', function (assert) {
assert.expect(2);
// takes precedence
_ember.default.Test.adapter = {
exception: function (error) {
assert.ok(true, 'adapter called');
throw error;
}
};
_ember.default.onerror = function (error) {
assert.ok(false, 'onerror was NEVER called');
throw error;
};
assert.throws(runThatThrows, Error);
});
}
QUnit.test('Ember.run does not swallow exceptions by default (Ember.testing = true)', function () {
_ember.default.testing = true;
var error = new Error('the error');
throws(function () {
_ember.default.run(function () {
throw error;
});
}, error);
});
QUnit.test('Ember.run does not swallow exceptions by default (Ember.testing = false)', function () {
_ember.default.testing = false;
var error = new Error('the error');
throws(function () {
_ember.default.run(function () {
throw error;
});
}, error);
});
});
QUnit.module('ESLint | ember/tests/error_handler_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/error_handler_test.js should pass ESLint\n\n');
});
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);
});
QUnit.module('ESLint | ember/tests/global-api-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/global-api-test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _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 testUnboundDashedHelpersRegisteredOnTheContainerCanBeLateInvoked(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 testBoundHelpersRegisteredOnTheContainerCanBeLateInvoked(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 testUndashedHelpersRegisteredOnTheContainerCanBeInvoked(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 testHelpersCanReceiveInjections(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));
});
QUnit.module('ESLint | ember/tests/helpers/helper_registration_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/helpers/helper_registration_test.js should pass ESLint\n\n');
});
enifed('ember/tests/helpers/link_to_test', ['ember-babel', 'ember-console', 'internal-test-helpers', 'ember-runtime', 'ember-metal', 'ember-routing', 'ember-views', 'ember/features'], function (_emberBabel, _emberConsole, _internalTestHelpers, _emberRuntime, _emberMetal, _emberRouting, _emberViews, _features) {
'use strict';
// IE includes the host name
function normalizeUrl(url) {
return url.replace(/https?:\/\/[^\/]+/, '');
}
function shouldNotBeActive(assert, element) {
checkActive(assert, element, false);
}
function shouldBeActive(assert, element) {
checkActive(assert, element, true);
}
function checkActive(assert, element, active) {
var classList = element.attr('class');
assert.equal(classList.indexOf('active') > -1, active, element + ' active should be ' + active);
}
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper - basic tests', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this));
_this.router.map(function () {
this.route('about');
});
_this.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}\n {{#link-to \'index\' id=\'self-link\'}}Self{{/link-to}}\n ');
_this.addTemplate('about', '\n About \n {{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}\n {{#link-to \'about\' id=\'self-link\'}}Self{{/link-to}}\n ');
return _this;
}
_class.prototype['@test The {{link-to}} helper moves into the named route'] = function testTheLinkToHelperMovesIntoTheNamedRoute(assert) {
this.visit('/');
assert.equal(this.$('h3:contains(Home)').length, 1, 'The home template was rendered');
assert.equal(this.$('#self-link.active').length, 1, 'The self-link was rendered with active class');
assert.equal(this.$('#about-link:not(.active)').length, 1, 'The other link was rendered without active class');
this.click('#about-link');
assert.equal(this.$('h3:contains(About)').length, 1, 'The about template was rendered');
assert.equal(this.$('#self-link.active').length, 1, 'The self-link was rendered with active class');
assert.equal(this.$('#home-link:not(.active)').length, 1, 'The other link was rendered without active class');
};
_class.prototype['@test the {{link-to}} helper doesn\'t add an href when the tagName isn\'t \'a\''] = function (assert) {
this.addTemplate('index', '\n {{#link-to \'about\' id=\'about-link\' tagName=\'div\'}}About{{/link-to}}\n ');
this.visit('/');
assert.equal(this.$('#about-link').attr('href'), undefined, 'there is no href attribute');
};
_class.prototype['@test the {{link-to}} applies a \'disabled\' class when disabled'] = function (assert) {
this.addTemplate('index', '\n {{#link-to "about" id="about-link-static" disabledWhen="shouldDisable"}}About{{/link-to}}\n {{#link-to "about" id="about-link-dynamic" disabledWhen=dynamicDisabledWhen}}About{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
shouldDisable: true,
dynamicDisabledWhen: 'shouldDisable'
}));
this.visit('/');
assert.equal(this.$('#about-link-static.disabled').length, 1, 'The static link is disabled when its disabledWhen is true');
assert.equal(this.$('#about-link-dynamic.disabled').length, 1, 'The dynamic link is disabled when its disabledWhen is true');
var controller = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
return controller.set('dynamicDisabledWhen', false);
});
assert.equal(this.$('#about-link-dynamic.disabled').length, 0, 'The dynamic link is re-enabled when its disabledWhen becomes false');
};
_class.prototype['@test the {{link-to}} doesn\'t apply a \'disabled\' class if disabledWhen is not provided'] = function (assert) {
this.addTemplate('index', '{{#link-to "about" id="about-link"}}About{{/link-to}}');
this.visit('/');
assert.ok(!this.$('#about-link').hasClass('disabled'), 'The link is not disabled if disabledWhen not provided');
};
_class.prototype['@test the {{link-to}} helper supports a custom disabledClass'] = function (assert) {
this.addTemplate('index', '\n {{#link-to "about" id="about-link" disabledWhen=true disabledClass="do-not-want"}}About{{/link-to}}\n ');
this.visit('/');
assert.equal(this.$('#about-link.do-not-want').length, 1, 'The link can apply a custom disabled class');
};
_class.prototype['@test the {{link-to}} helper supports a custom disabledClass set via bound param'] = function (assert) {
this.addTemplate('index', '\n {{#link-to "about" id="about-link" disabledWhen=true disabledClass=disabledClass}}About{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
disabledClass: 'do-not-want'
}));
this.visit('/');
assert.equal(this.$('#about-link.do-not-want').length, 1, 'The link can apply a custom disabled class via bound param');
};
_class.prototype['@test the {{link-to}} helper does not respond to clicks when disabled'] = function (assert) {
this.addTemplate('index', '\n {{#link-to "about" id="about-link" disabledWhen=true}}About{{/link-to}}\n ');
this.visit('/');
this.click('#about-link');
assert.equal(this.$('h3:contains(About)').length, 0, 'Transitioning did not occur');
};
_class.prototype['@test the {{link-to}} helper responds to clicks according to its disabledWhen bound param'] = function (assert) {
this.addTemplate('index', '\n {{#link-to "about" id="about-link" disabledWhen=disabledWhen}}About{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
disabledWhen: true
}));
this.visit('/');
this.click('#about-link');
assert.equal(this.$('h3:contains(About)').length, 0, 'Transitioning did not occur');
var controller = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
return controller.set('disabledWhen', false);
});
this.click('#about-link');
assert.equal(this.$('h3:contains(About)').length, 1, 'Transitioning did occur when disabledWhen became false');
};
_class.prototype['@test The {{link-to}} helper supports a custom activeClass'] = function (assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}\n {{#link-to \'index\' id=\'self-link\' activeClass=\'zomg-active\'}}Self{{/link-to}}\n ');
this.visit('/');
assert.equal(this.$('h3:contains(Home)').length, 1, 'The home template was rendered');
assert.equal(this.$('#self-link.zomg-active').length, 1, 'The self-link was rendered with active class');
assert.equal(this.$('#about-link:not(.active)').length, 1, 'The other link was rendered without active class');
};
_class.prototype['@test The {{link-to}} helper supports a custom activeClass from a bound param'] = function (assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}\n {{#link-to \'index\' id=\'self-link\' activeClass=activeClass}}Self{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
activeClass: 'zomg-active'
}));
this.visit('/');
assert.equal(this.$('h3:contains(Home)').length, 1, 'The home template was rendered');
assert.equal(this.$('#self-link.zomg-active').length, 1, 'The self-link was rendered with active class');
assert.equal(this.$('#about-link:not(.active)').length, 1, 'The other link was rendered without active class');
};
_class.prototype['@test The {{link-to}} helper supports \'classNameBindings\' with custom values [GH #11699]'] = function (assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\' classNameBindings=\'foo:foo-is-true:foo-is-false\'}}About{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
foo: false
}));
this.visit('/');
assert.equal(this.$('#about-link.foo-is-false').length, 1, 'The about-link was rendered with the falsy class');
var controller = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
return controller.set('foo', true);
});
assert.equal(this.$('#about-link.foo-is-true').length, 1, 'The about-link was rendered with the truthy class after toggling the property');
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper - location hooks', function (_ApplicationTestCase2) {
(0, _emberBabel.inherits)(_class2, _ApplicationTestCase2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
var _this2 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase2.call(this));
_this2.updateCount = 0;
_this2.replaceCount = 0;
var testContext = _this2;
_this2.add('location:none', _emberRouting.NoneLocation.extend({
setURL: function () {
testContext.updateCount++;
return this._super.apply(this, arguments);
},
replaceURL: function () {
testContext.replaceCount++;
return this._super.apply(this, arguments);
}
}));
_this2.router.map(function () {
this.route('about');
});
_this2.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}\n {{#link-to \'index\' id=\'self-link\'}}Self{{/link-to}}\n ');
_this2.addTemplate('about', '\n About \n {{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}\n {{#link-to \'about\' id=\'self-link\'}}Self{{/link-to}}\n ');
return _this2;
}
_class2.prototype.visit = function visit() {
var _ApplicationTestCase3;
(_ApplicationTestCase3 = _ApplicationTestCase2.prototype.visit).call.apply(_ApplicationTestCase3, [this].concat(Array.prototype.slice.call(arguments)));
this.updateCountAfterVisit = this.updateCount;
this.replaceCountAfterVisit = this.replaceCount;
};
_class2.prototype['@test The {{link-to}} helper supports URL replacement'] = function testTheLinkToHelperSupportsURLReplacement(assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\' replace=true}}About{{/link-to}}\n ');
this.visit('/');
this.click('#about-link');
assert.equal(this.updateCount, this.updateCountAfterVisit, 'setURL should not be called');
assert.equal(this.replaceCount, this.replaceCountAfterVisit + 1, 'replaceURL should be called once');
};
_class2.prototype['@test The {{link-to}} helper supports URL replacement via replace=boundTruthyThing'] = function testTheLinkToHelperSupportsURLReplacementViaReplaceBoundTruthyThing(assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\' replace=boundTruthyThing}}About{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
boundTruthyThing: true
}));
this.visit('/');
this.click('#about-link');
assert.equal(this.updateCount, this.updateCountAfterVisit, 'setURL should not be called');
assert.equal(this.replaceCount, this.replaceCountAfterVisit + 1, 'replaceURL should be called once');
};
_class2.prototype['@test The {{link-to}} helper supports setting replace=boundFalseyThing'] = function testTheLinkToHelperSupportsSettingReplaceBoundFalseyThing(assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\' replace=boundFalseyThing}}About{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
boundFalseyThing: false
}));
this.visit('/');
this.click('#about-link');
assert.equal(this.updateCount, this.updateCountAfterVisit + 1, 'setURL should be called');
assert.equal(this.replaceCount, this.replaceCountAfterVisit, 'replaceURL should not be called');
};
return _class2;
}(_internalTestHelpers.ApplicationTestCase));
if (_features.EMBER_IMPROVED_INSTRUMENTATION) {
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper with EMBER_IMPROVED_INSTRUMENTATION', function (_ApplicationTestCase4) {
(0, _emberBabel.inherits)(_class3, _ApplicationTestCase4);
function _class3() {
(0, _emberBabel.classCallCheck)(this, _class3);
var _this3 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase4.call(this));
_this3.router.map(function () {
this.route('about');
});
_this3.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}\n {{#link-to \'index\' id=\'self-link\'}}Self{{/link-to}}\n ');
_this3.addTemplate('about', '\n About \n {{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}\n {{#link-to \'about\' id=\'self-link\'}}Self{{/link-to}}\n ');
_this3.visit('/');
return _this3;
}
_class3.prototype['@test The {{link-to}} helper fires an interaction event'] = function testTheLinkToHelperFiresAnInteractionEvent(assert) {
assert.expect(2);
(0, _emberMetal.instrumentationSubscribe)('interaction.link-to', {
before: function () {
assert.ok(true, 'instrumentation subscriber was called');
},
after: function () {
assert.ok(true, 'instrumentation subscriber was called');
}
});
this.click('#about-link');
};
_class3.prototype['@test The {{link-to}} helper interaction event includes the route name'] = function testTheLinkToHelperInteractionEventIncludesTheRouteName(assert) {
assert.expect(2);
(0, _emberMetal.instrumentationSubscribe)('interaction.link-to', {
before: function (name, timestamp, _ref) {
var routeName = _ref.routeName;
assert.equal(routeName, 'about', 'instrumentation subscriber was passed route name');
},
after: function (name, timestamp, _ref2) {
var routeName = _ref2.routeName;
assert.equal(routeName, 'about', 'instrumentation subscriber was passed route name');
}
});
this.click('#about-link');
};
_class3.prototype['@test The {{link-to}} helper interaction event includes the transition in the after hook'] = function testTheLinkToHelperInteractionEventIncludesTheTransitionInTheAfterHook(assert) {
assert.expect(1);
(0, _emberMetal.instrumentationSubscribe)('interaction.link-to', {
before: function () {},
after: function (name, timestamp, _ref3) {
var transition = _ref3.transition;
assert.equal(transition.targetName, 'about', 'instrumentation subscriber was passed route name');
}
});
this.click('#about-link');
};
return _class3;
}(_internalTestHelpers.ApplicationTestCase));
}
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper - nested routes and link-to arguments', function (_ApplicationTestCase5) {
(0, _emberBabel.inherits)(_class4, _ApplicationTestCase5);
function _class4() {
(0, _emberBabel.classCallCheck)(this, _class4);
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase5.apply(this, arguments));
}
_class4.prototype['@test The {{link-to}} helper supports leaving off .index for nested routes'] = function testTheLinkToHelperSupportsLeavingOffIndexForNestedRoutes(assert) {
this.router.map(function () {
this.route('about', function () {
this.route('item');
});
});
this.addTemplate('about', 'About {{outlet}}');
this.addTemplate('about.index', 'Index
');
this.addTemplate('about.item', '{{#link-to \'about\'}}About{{/link-to}}
');
this.visit('/about/item');
assert.equal(normalizeUrl(this.$('#item a').attr('href')), '/about');
};
_class4.prototype['@test The {{link-to}} helper supports currentWhen (DEPRECATED)'] = function testTheLinkToHelperSupportsCurrentWhenDEPRECATED(assert) {
expectDeprecation('Usage of `currentWhen` is deprecated, use `current-when` instead.');
this.router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('item');
});
this.addTemplate('index', 'Home {{outlet}}');
this.addTemplate('index.about', '\n {{#link-to \'item\' id=\'other-link\' currentWhen=\'index\'}}ITEM{{/link-to}}\n ');
this.visit('/about');
assert.equal(this.$('#other-link.active').length, 1, 'The link is active since current-when is a parent route');
};
_class4.prototype['@test The {{link-to}} helper supports custom, nested, current-when'] = function (assert) {
this.router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('item');
});
this.addTemplate('index', 'Home {{outlet}}');
this.addTemplate('index.about', '\n {{#link-to \'item\' id=\'other-link\' current-when=\'index\'}}ITEM{{/link-to}}\n ');
this.visit('/about');
equal(this.$('#other-link.active').length, 1, 'The link is active since current-when is a parent route');
};
_class4.prototype['@test The {{link-to}} helper does not disregard current-when when it is given explicitly for a route'] = function (assert) {
this.router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('items', function () {
this.route('item');
});
});
this.addTemplate('index', 'Home {{outlet}}');
this.addTemplate('index.about', '\n {{#link-to \'items\' id=\'other-link\' current-when=\'index\'}}ITEM{{/link-to}}\n ');
this.visit('/about');
assert.equal(this.$('#other-link.active').length, 1, 'The link is active when current-when is given for explicitly for a route');
};
_class4.prototype['@test The {{link-to}} helper does not disregard current-when when it is set via a bound param'] = function testTheLinkToHelperDoesNotDisregardCurrentWhenWhenItIsSetViaABoundParam(assert) {
this.router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('items', function () {
this.route('item');
});
});
this.add('controller:index.about', _emberRuntime.Controller.extend({
currentWhen: 'index'
}));
this.addTemplate('index', 'Home {{outlet}}');
this.addTemplate('index.about', '{{#link-to \'items\' id=\'other-link\' current-when=currentWhen}}ITEM{{/link-to}}');
this.visit('/about');
assert.equal(this.$('#other-link.active').length, 1, 'The link is active when current-when is given for explicitly for a route');
};
_class4.prototype['@test The {{link-to}} helper supports multiple current-when routes'] = function testTheLinkToHelperSupportsMultipleCurrentWhenRoutes(assert) {
this.router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('item');
this.route('foo');
});
this.addTemplate('index', 'Home {{outlet}}');
this.addTemplate('index.about', '{{#link-to \'item\' id=\'link1\' current-when=\'item index\'}}ITEM{{/link-to}}');
this.addTemplate('item', '{{#link-to \'item\' id=\'link2\' current-when=\'item index\'}}ITEM{{/link-to}}');
this.addTemplate('foo', '{{#link-to \'item\' id=\'link3\' current-when=\'item index\'}}ITEM{{/link-to}}');
this.visit('/about');
assert.equal(this.$('#link1.active').length, 1, 'The link is active since current-when contains the parent route');
this.visit('/item');
assert.equal(this.$('#link2.active').length, 1, 'The link is active since you are on the active route');
this.visit('/foo');
assert.equal(this.$('#link3.active').length, 0, 'The link is not active since current-when does not contain the active route');
};
_class4.prototype['@test The {{link-to}} helper supports boolean values for current-when'] = function testTheLinkToHelperSupportsBooleanValuesForCurrentWhen(assert) {
this.router.map(function (match) {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('item');
});
this.addTemplate('index', 'Home {{outlet}}');
this.addTemplate('index.about', '{{#link-to \'item\' id=\'other-link\' current-when=true}}ITEM{{/link-to}}');
this.visit('/about');
assert.equal(this.$('#other-link').length, 1, 'The link is active since current-when is true');
};
_class4.prototype['@test The {{link-to}} helper defaults to bubbling'] = function testTheLinkToHelperDefaultsToBubbling(assert) {
this.addTemplate('about', '\n \n {{#link-to \'about.contact\' id=\'about-contact\'}}About{{/link-to}}\n
\n {{outlet}}\n ');
this.addTemplate('about.contact', '\n \n ');
this.router.map(function () {
this.route('about', function () {
this.route('contact');
});
});
var hidden = 0;
this.add('route:about', _emberRouting.Route.extend({
actions: {
hide: function () {
hidden++;
}
}
}));
this.visit('/about');
this.click('#about-contact');
assert.equal(this.$('#contact').text(), 'Contact', 'precond - the link worked');
assert.equal(hidden, 1, 'The link bubbles');
};
_class4.prototype['@test The {{link-to}} helper supports bubbles=false'] = function (assert) {
this.addTemplate('about', '\n \n {{#link-to \'about.contact\' id=\'about-contact\' bubbles=false}}\n About\n {{/link-to}}\n
\n {{outlet}}\n ');
this.addTemplate('about.contact', '');
this.router.map(function () {
this.route('about', function () {
this.route('contact');
});
});
var hidden = 0;
this.add('route:about', _emberRouting.Route.extend({
actions: {
hide: function () {
hidden++;
}
}
}));
this.visit('/about');
this.click('#about-contact');
assert.equal(this.$('#contact').text(), 'Contact', 'precond - the link worked');
assert.equal(hidden, 0, "The link didn't bubble");
};
_class4.prototype['@test The {{link-to}} helper supports bubbles=boundFalseyThing'] = function (assert) {
this.addTemplate('about', '\n \n {{#link-to \'about.contact\' id=\'about-contact\' bubbles=boundFalseyThing}}\n About\n {{/link-to}}\n
\n {{outlet}}\n ');
this.addTemplate('about.contact', '');
this.add('controller:about', _emberRuntime.Controller.extend({
boundFalseyThing: false
}));
this.router.map(function () {
this.route('about', function () {
this.route('contact');
});
});
var hidden = 0;
this.add('route:about', _emberRouting.Route.extend({
actions: {
hide: function () {
hidden++;
}
}
}));
this.visit('/about');
this.click('#about-contact');
assert.equal(this.$('#contact').text(), 'Contact', 'precond - the link worked');
assert.equal(hidden, 0, "The link didn't bubble");
};
_class4.prototype['@test The {{link-to}} helper moves into the named route with context'] = function (assert) {
this.router.map(function () {
this.route('about');
this.route('item', { path: '/item/:id' });
});
this.addTemplate('about', '\n List \n \n {{#each model as |person|}}\n \n {{#link-to \'item\' person}}\n {{person.name}}\n {{/link-to}}\n \n {{/each}}\n \n {{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}\n ');
this.addTemplate('item', '\n Item \n {{model.name}}
\n {{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}\n ');
this.addTemplate('index', '\n Home \n {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}\n ');
this.add('route:about', _emberRouting.Route.extend({
model: function () {
return [{ id: 'yehuda', name: 'Yehuda Katz' }, { id: 'tom', name: 'Tom Dale' }, { id: 'erik', name: 'Erik Brynroflsson' }];
}
}));
this.visit('/about');
assert.equal(this.$('h3:contains(List)').length, 1, 'The home template was rendered');
assert.equal(normalizeUrl(this.$('#home-link').attr('href')), '/', 'The home link points back at /');
this.click('li a:contains(Yehuda)');
assert.equal(this.$('h3:contains(Item)').length, 1, 'The item template was rendered');
assert.equal(this.$('p').text(), 'Yehuda Katz', 'The name is correct');
this.click('#home-link');
this.click('#about-link');
assert.equal(normalizeUrl(this.$('li a:contains(Yehuda)').attr('href')), '/item/yehuda');
assert.equal(normalizeUrl(this.$('li a:contains(Tom)').attr('href')), '/item/tom');
assert.equal(normalizeUrl(this.$('li a:contains(Erik)').attr('href')), '/item/erik');
this.click('li a:contains(Erik)');
assert.equal(this.$('h3:contains(Item)').length, 1, 'The item template was rendered');
assert.equal(this.$('p').text(), 'Erik Brynroflsson', 'The name is correct');
};
_class4.prototype['@test The {{link-to}} helper binds some anchor html tag common attributes'] = function (assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'index\' id=\'self-link\' title=\'title-attr\' rel=\'rel-attr\' tabindex=\'-1\'}}\n Self\n {{/link-to}}\n ');
this.visit('/');
var link = this.$('#self-link');
assert.equal(link.attr('title'), 'title-attr', 'The self-link contains title attribute');
assert.equal(link.attr('rel'), 'rel-attr', 'The self-link contains rel attribute');
assert.equal(link.attr('tabindex'), '-1', 'The self-link contains tabindex attribute');
};
_class4.prototype['@test The {{link-to}} helper supports \'target\' attribute'] = function (assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'index\' id=\'self-link\' target=\'_blank\'}}Self{{/link-to}}\n ');
this.visit('/');
var link = this.$('#self-link');
assert.equal(link.attr('target'), '_blank', 'The self-link contains `target` attribute');
};
_class4.prototype['@test The {{link-to}} helper supports \'target\' attribute specified as a bound param'] = function (assert) {
this.addTemplate('index', 'Home {{#link-to \'index\' id=\'self-link\' target=boundLinkTarget}}Self{{/link-to}}');
this.add('controller:index', _emberRuntime.Controller.extend({
boundLinkTarget: '_blank'
}));
this.visit('/');
var link = this.$('#self-link');
assert.equal(link.attr('target'), '_blank', 'The self-link contains `target` attribute');
};
_class4.prototype['@test the {{link-to}} helper calls preventDefault'] = function (assert) {
this.router.map(function () {
this.route('about');
});
this.addTemplate('index', '\n {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}\n ');
this.visit('/');
var event = _emberViews.jQuery.Event('click');
this.$('#about-link').trigger(event);
assert.equal(event.isDefaultPrevented(), true, 'should preventDefault');
};
_class4.prototype['@test the {{link-to}} helper does not call preventDefault if \'preventDefault=false\' is passed as an option'] = function (assert) {
this.router.map(function () {
this.route('about');
});
this.addTemplate('index', '\n {{#link-to \'about\' id=\'about-link\' preventDefault=false}}About{{/link-to}}\n ');
this.visit('/');
var event = _emberViews.jQuery.Event('click');
this.$('#about-link').trigger(event);
assert.equal(event.isDefaultPrevented(), false, 'should not preventDefault');
};
_class4.prototype['@test the {{link-to}} helper does not call preventDefault if \'preventDefault=boundFalseyThing\' is passed as an option'] = function (assert) {
this.router.map(function () {
this.route('about');
});
this.addTemplate('index', '\n {{#link-to \'about\' id=\'about-link\' preventDefault=boundFalseyThing}}About{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
boundFalseyThing: false
}));
this.visit('/');
var event = _emberViews.jQuery.Event('click');
this.$('#about-link').trigger(event);
equal(event.isDefaultPrevented(), false, 'should not preventDefault');
};
_class4.prototype['@test The {{link-to}} helper does not call preventDefault if \'target\' attribute is provided'] = function (assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'index\' id=\'self-link\' target=\'_blank\'}}Self{{/link-to}}\n ');
this.visit('/');
var event = _emberViews.jQuery.Event('click');
this.$('#self-link').trigger(event);
assert.equal(event.isDefaultPrevented(), false, 'should not preventDefault when target attribute is specified');
};
_class4.prototype['@test The {{link-to}} helper should preventDefault when \'target = _self\''] = function (assert) {
this.addTemplate('index', '\n Home \n {{#link-to \'index\' id=\'self-link\' target=\'_self\'}}Self{{/link-to}}\n ');
this.visit('/');
var event = _emberViews.jQuery.Event('click');
this.$('#self-link').trigger(event);
equal(event.isDefaultPrevented(), true, 'should preventDefault when target attribute is `_self`');
};
_class4.prototype['@test The {{link-to}} helper should not transition if target is not equal to _self or empty'] = function (assert) {
this.addTemplate('index', '\n {{#link-to \'about\' id=\'about-link\' replace=true target=\'_blank\'}}\n About\n {{/link-to}}\n ');
this.router.map(function () {
this.route('about');
});
this.visit('/');
this.click('#about-link');
var currentRouteName = this.applicationInstance.lookup('controller:application').get('currentRouteName');
assert.notEqual(currentRouteName, 'about', 'link-to should not transition if target is not equal to _self or empty');
};
_class4.prototype['@test The {{link-to}} helper accepts string/numeric arguments'] = function (assert) {
this.router.map(function () {
this.route('filter', { path: '/filters/:filter' });
this.route('post', { path: '/post/:post_id' });
this.route('repo', { path: '/repo/:owner/:name' });
});
this.add('controller:filter', _emberRuntime.Controller.extend({
filter: 'unpopular',
repo: { owner: 'ember', name: 'ember.js' },
post_id: 123
}));
this.addTemplate('filter', '\n {{filter}}
\n {{#link-to "filter" "unpopular" id="link"}}Unpopular{{/link-to}}\n {{#link-to "filter" filter id="path-link"}}Unpopular{{/link-to}}\n {{#link-to "post" post_id id="post-path-link"}}Post{{/link-to}}\n {{#link-to "post" 123 id="post-number-link"}}Post{{/link-to}}\n {{#link-to "repo" repo id="repo-object-link"}}Repo{{/link-to}}\n ');
this.visit('/filters/popular');
assert.equal(normalizeUrl(this.$('#link').attr('href')), '/filters/unpopular');
assert.equal(normalizeUrl(this.$('#path-link').attr('href')), '/filters/unpopular');
assert.equal(normalizeUrl(this.$('#post-path-link').attr('href')), '/post/123');
assert.equal(normalizeUrl(this.$('#post-number-link').attr('href')), '/post/123');
assert.equal(normalizeUrl(this.$('#repo-object-link').attr('href')), '/repo/ember/ember.js');
};
_class4.prototype['@test Issue 4201 - Shorthand for route.index shouldn\'t throw errors about context arguments'] = function (assert) {
assert.expect(2);
this.router.map(function () {
this.route('lobby', function () {
this.route('index', { path: ':lobby_id' });
this.route('list');
});
});
this.add('route:lobby.index', _emberRouting.Route.extend({
model: function (params) {
assert.equal(params.lobby_id, 'foobar');
return params.lobby_id;
}
}));
this.addTemplate('lobby.index', '\n {{#link-to \'lobby\' \'foobar\' id=\'lobby-link\'}}Lobby{{/link-to}}\n ');
this.addTemplate('lobby.list', '\n {{#link-to \'lobby\' \'foobar\' id=\'lobby-link\'}}Lobby{{/link-to}}\n ');
this.visit('/lobby/list');
this.click('#lobby-link');
shouldBeActive(assert, this.$('#lobby-link'));
};
_class4.prototype['@test Quoteless route param performs property lookup'] = function (assert) {
var _this5 = this;
this.router.map(function () {
this.route('about');
});
this.addTemplate('index', '\n {{#link-to \'index\' id=\'string-link\'}}string{{/link-to}}\n {{#link-to foo id=\'path-link\'}}path{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
foo: 'index'
}));
var assertEquality = function (href) {
assert.equal(normalizeUrl(_this5.$('#string-link').attr('href')), '/');
assert.equal(normalizeUrl(_this5.$('#path-link').attr('href')), href);
};
this.visit('/');
assertEquality('/');
var controller = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
return controller.set('foo', 'about');
});
assertEquality('/about');
};
_class4.prototype['@test The {{link-to}} helper refreshes href element when one of params changes'] = function (assert) {
this.router.map(function () {
this.route('post', { path: '/posts/:post_id' });
});
var post = { id: '1' };
var secondPost = { id: '2' };
this.addTemplate('index', '\n {{#link-to "post" post id="post"}}post{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend());
this.visit('/');
var indexController = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
return indexController.set('post', post);
});
assert.equal(normalizeUrl(this.$('#post').attr('href')), '/posts/1', 'precond - Link has rendered href attr properly');
this.runTask(function () {
return indexController.set('post', secondPost);
});
assert.equal(this.$('#post').attr('href'), '/posts/2', 'href attr was updated after one of the params had been changed');
this.runTask(function () {
return indexController.set('post', null);
});
assert.equal(this.$('#post').attr('href'), '#', 'href attr becomes # when one of the arguments in nullified');
};
_class4.prototype['@test The {{link-to}} helper is active when a route is active'] = function (assert) {
this.router.map(function () {
this.route('about', function () {
this.route('item');
});
});
this.addTemplate('about', '\n \n {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}\n {{#link-to \'about.item\' id=\'item-link\'}}Item{{/link-to}}\n {{outlet}}\n
\n ');
this.visit('/about');
assert.equal(this.$('#about-link.active').length, 1, 'The about route link is active');
assert.equal(this.$('#item-link.active').length, 0, 'The item route link is inactive');
this.visit('/about/item');
assert.equal(this.$('#about-link.active').length, 1, 'The about route link is active');
assert.equal(this.$('#item-link.active').length, 1, 'The item route link is active');
};
_class4.prototype['@test The {{link-to}} helper works in an #each\'d array of string route names'] = function (assert) {
var _this6 = this;
this.router.map(function () {
this.route('foo');
this.route('bar');
this.route('rar');
});
this.add('controller:index', _emberRuntime.Controller.extend({
routeNames: (0, _emberRuntime.A)(['foo', 'bar', 'rar']),
route1: 'bar',
route2: 'foo'
}));
this.addTemplate('index', '\n {{#each routeNames as |routeName|}}\n {{#link-to routeName}}{{routeName}}{{/link-to}}\n {{/each}}\n {{#each routeNames as |r|}}\n {{#link-to r}}{{r}}{{/link-to}}\n {{/each}}\n {{#link-to route1}}a{{/link-to}}\n {{#link-to route2}}b{{/link-to}}\n ');
this.visit('/');
var linksEqual = function (links, expected) {
equal(links.length, expected.length, 'Has correct number of links');
var idx = void 0;
for (idx = 0; idx < links.length; idx++) {
var href = _this6.$(links[idx]).attr('href');
// Old IE includes the whole hostname as well
assert.equal(href.slice(-expected[idx].length), expected[idx], 'Expected link to be \'' + expected[idx] + '\', but was \'' + href + '\'');
}
};
linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/bar', '/foo']);
var indexController = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
return indexController.set('route1', 'rar');
});
linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/rar', '/foo']);
this.runTask(function () {
return indexController.routeNames.shiftObject();
});
linksEqual(this.$('a'), ['/bar', '/rar', '/bar', '/rar', '/rar', '/foo']);
};
_class4.prototype['@test The non-block form {{link-to}} helper moves into the named route'] = function (assert) {
assert.expect(3);
this.router.map(function () {
this.route('contact');
});
this.addTemplate('index', '\n Home \n {{link-to \'Contact us\' \'contact\' id=\'contact-link\'}}\n {{#link-to \'index\' id=\'self-link\'}}Self{{/link-to}}\n ');
this.addTemplate('contact', '\n Contact \n {{link-to \'Home\' \'index\' id=\'home-link\'}}\n {{link-to \'Self\' \'contact\' id=\'self-link\'}}\n ');
this.visit('/');
this.click('#contact-link');
assert.equal(this.$('h3:contains(Contact)').length, 1, 'The contact template was rendered');
assert.equal(this.$('#self-link.active').length, 1, 'The self-link was rendered with active class');
assert.equal(this.$('#home-link:not(.active)').length, 1, 'The other link was rendered without active class');
};
_class4.prototype['@test The non-block form {{link-to}} helper updates the link text when it is a binding'] = function (assert) {
assert.expect(8);
this.router.map(function () {
this.route('contact');
});
this.add('controller:index', _emberRuntime.Controller.extend({
contactName: 'Jane'
}));
this.addTemplate('index', '\n Home \n {{link-to contactName \'contact\' id=\'contact-link\'}}\n {{#link-to \'index\' id=\'self-link\'}}Self{{/link-to}}\n ');
this.addTemplate('contact', '\n Contact \n {{link-to \'Home\' \'index\' id=\'home-link\'}}\n {{link-to \'Self\' \'contact\' id=\'self-link\'}}\n ');
this.visit('/');
assert.equal(this.$('#contact-link:contains(Jane)').length, 1, 'The link title is correctly resolved');
var controller = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
return controller.set('contactName', 'Joe');
});
assert.equal(this.$('#contact-link:contains(Joe)').length, 1, 'The link title is correctly updated when the bound property changes');
this.runTask(function () {
return controller.set('contactName', 'Robert');
});
assert.equal(this.$('#contact-link:contains(Robert)').length, 1, 'The link title is correctly updated when the bound property changes a second time');
this.click('#contact-link');
assert.equal(this.$('h3:contains(Contact)').length, 1, 'The contact template was rendered');
assert.equal(this.$('#self-link.active').length, 1, 'The self-link was rendered with active class');
assert.equal(this.$('#home-link:not(.active)').length, 1, 'The other link was rendered without active class');
this.click('#home-link');
assert.equal(this.$('h3:contains(Home)').length, 1, 'The index template was rendered');
assert.equal(this.$('#contact-link:contains(Robert)').length, 1, 'The link title is correctly updated when the route changes');
};
_class4.prototype['@test The non-block form {{link-to}} helper moves into the named route with context'] = function (assert) {
assert.expect(5);
this.router.map(function () {
this.route('item', { path: '/item/:id' });
});
this.add('route:index', _emberRouting.Route.extend({
model: function () {
return [{ id: 'yehuda', name: 'Yehuda Katz' }, { id: 'tom', name: 'Tom Dale' }, { id: 'erik', name: 'Erik Brynroflsson' }];
}
}));
this.addTemplate('index', '\n Home \n \n {{#each model as |person|}}\n \n {{link-to person.name \'item\' person}}\n \n {{/each}}\n \n ');
this.addTemplate('item', '\n Item \n {{model.name}}
\n {{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}\n ');
this.visit('/');
this.click('li a:contains(Yehuda)');
assert.equal(this.$('h3:contains(Item)').length, 1, 'The item template was rendered');
assert.equal(this.$('p').text(), 'Yehuda Katz', 'The name is correct');
this.click('#home-link');
assert.equal(normalizeUrl(this.$('li a:contains(Yehuda)').attr('href')), '/item/yehuda');
assert.equal(normalizeUrl(this.$('li a:contains(Tom)').attr('href')), '/item/tom');
assert.equal(normalizeUrl(this.$('li a:contains(Erik)').attr('href')), '/item/erik');
};
_class4.prototype['@test The non-block form {{link-to}} performs property lookup'] = function (assert) {
var _this7 = this;
this.router.map(function () {
this.route('about');
});
this.addTemplate('index', '\n {{link-to \'string\' \'index\' id=\'string-link\'}}\n {{link-to path foo id=\'path-link\'}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
foo: 'index'
}));
this.visit('/');
var assertEquality = function (href) {
assert.equal(normalizeUrl(_this7.$('#string-link').attr('href')), '/');
assert.equal(normalizeUrl(_this7.$('#path-link').attr('href')), href);
};
assertEquality('/');
var controller = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
return controller.set('foo', 'about');
});
assertEquality('/about');
};
_class4.prototype['@test The non-block form {{link-to}} protects against XSS'] = function (assert) {
this.addTemplate('application', '{{link-to display \'index\' id=\'link\'}}');
this.add('controller:application', _emberRuntime.Controller.extend({
display: 'blahzorz'
}));
this.visit('/');
assert.equal(this.$('#link').text(), 'blahzorz');
var controller = this.applicationInstance.lookup('controller:application');
this.runTask(function () {
return controller.set('display', 'BLAMMO ');
});
assert.equal(this.$('#link').text(), 'BLAMMO ');
assert.equal(this.$('b').length, 0);
};
_class4.prototype['@test the {{link-to}} helper does not throw an error if its route has exited'] = function (assert) {
assert.expect(0);
this.router.map(function () {
this.route('post', { path: 'post/:post_id' });
});
this.addTemplate('application', '\n {{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}\n {{#link-to \'post\' defaultPost id=\'default-post-link\'}}Default Post{{/link-to}}\n {{#if currentPost}}\n {{#link-to \'post\' currentPost id=\'current-post-link\'}}Current Post{{/link-to}}\n {{/if}}\n ');
this.add('controller:application', _emberRuntime.Controller.extend({
defaultPost: { id: 1 },
postController: _emberRuntime.inject.controller('post'),
currentPost: (0, _emberMetal.alias)('postController.model')
}));
this.add('controller:post', _emberRuntime.Controller.extend());
this.add('route:post', _emberRouting.Route.extend({
model: function () {
return { id: 2 };
},
serialize: function (model) {
return { post_id: model.id };
}
}));
this.visit('/');
this.click('#default-post-link');
this.click('#home-link');
this.click('#current-post-link');
this.click('#home-link');
};
_class4.prototype['@test {{link-to}} active property respects changing parent route context'] = function (assert) {
this.router.map(function () {
this.route('things', { path: '/things/:name' }, function () {
this.route('other');
});
});
this.addTemplate('application', '\n {{link-to \'OMG\' \'things\' \'omg\' id=\'omg-link\'}}\n {{link-to \'LOL\' \'things\' \'lol\' id=\'lol-link\'}}\n ');
this.visit('/things/omg');
shouldBeActive(assert, this.$('#omg-link'));
shouldNotBeActive(assert, this.$('#lol-link'));
this.visit('/things/omg/other');
shouldBeActive(assert, this.$('#omg-link'));
shouldNotBeActive(assert, this.$('#lol-link'));
};
_class4.prototype['@test {{link-to}} populates href with default query param values even without query-params object'] = function (assert) {
this.add('controller:index', _emberRuntime.Controller.extend({
queryParams: ['foo'],
foo: '123'
}));
this.addTemplate('index', '{{#link-to \'index\' id=\'the-link\'}}Index{{/link-to}}');
this.visit('/');
assert.equal(this.$('#the-link').attr('href'), '/', 'link has right href');
};
_class4.prototype['@test {{link-to}} populates href with default query param values with empty query-params object'] = function (assert) {
this.add('controller:index', _emberRuntime.Controller.extend({
queryParams: ['foo'],
foo: '123'
}));
this.addTemplate('index', '\n {{#link-to \'index\' (query-params) id=\'the-link\'}}Index{{/link-to}}\n ');
this.visit('/');
assert.equal(this.$('#the-link').attr('href'), '/', 'link has right href');
};
_class4.prototype['@test {{link-to}} with only query-params and a block updates when route changes'] = function (assert) {
this.router.map(function () {
this.route('about');
});
this.add('controller:application', _emberRuntime.Controller.extend({
queryParams: ['foo', 'bar'],
foo: '123',
bar: 'yes'
}));
this.addTemplate('application', '\n {{#link-to (query-params foo=\'456\' bar=\'NAW\') id=\'the-link\'}}Index{{/link-to}}\n ');
this.visit('/');
assert.equal(this.$('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');
this.visit('/about');
assert.equal(this.$('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
};
_class4.prototype['@test Block-less {{link-to}} with only query-params updates when route changes'] = function (assert) {
this.router.map(function () {
this.route('about');
});
this.add('controller:application', _emberRuntime.Controller.extend({
queryParams: ['foo', 'bar'],
foo: '123',
bar: 'yes'
}));
this.addTemplate('application', '\n {{link-to "Index" (query-params foo=\'456\' bar=\'NAW\') id=\'the-link\'}}\n ');
this.visit('/');
assert.equal(this.$('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');
this.visit('/about');
assert.equal(this.$('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
};
_class4.prototype['@test The {{link-to}} helper can use dynamic params'] = function (assert) {
this.router.map(function () {
this.route('foo', { path: 'foo/:some/:thing' });
this.route('bar', { path: 'bar/:some/:thing/:else' });
});
this.add('controller:index', _emberRuntime.Controller.extend({
init: function () {
this._super.apply(this, arguments);
this.dynamicLinkParams = ['foo', 'one', 'two'];
}
}));
this.addTemplate('index', '\n Home \n {{#link-to params=dynamicLinkParams id="dynamic-link"}}Dynamic{{/link-to}}\n ');
this.visit('/');
var link = this.$('#dynamic-link');
assert.equal(link.attr('href'), '/foo/one/two');
var controller = this.applicationInstance.lookup('controller:index');
this.runTask(function () {
controller.set('dynamicLinkParams', ['bar', 'one', 'two', 'three']);
});
assert.equal(link.attr('href'), '/bar/one/two/three');
};
_class4.prototype['@test GJ: {{link-to}} to a parent root model hook which performs a \'transitionTo\' has correct active class #13256'] = function (assert) {
assert.expect(1);
this.router.map(function () {
this.route('parent', function () {
this.route('child');
});
});
this.add('route:parent', _emberRouting.Route.extend({
afterModel: function (transition) {
this.transitionTo('parent.child');
}
}));
this.addTemplate('application', '\n {{link-to \'Parent\' \'parent\' id=\'parent-link\'}}\n ');
this.visit('/');
this.click('#parent-link');
shouldBeActive(assert, this.$('#parent-link'));
};
return _class4;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper - loading states and warnings', function (_ApplicationTestCase6) {
(0, _emberBabel.inherits)(_class5, _ApplicationTestCase6);
function _class5() {
(0, _emberBabel.classCallCheck)(this, _class5);
var _this8 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase6.call(this));
_this8._oldWarn = _emberConsole.default.warn;
_this8.warnCalled = false;
_emberConsole.default.warn = function () {
return _this8.warnCalled = true;
};
return _this8;
}
_class5.prototype.teardown = function teardown() {
_emberConsole.default.warn = this._oldWarn;
_ApplicationTestCase6.prototype.teardown.call(this);
};
_class5.prototype['@test link-to with null/undefined dynamic parameters are put in a loading state'] = function (assert) {
assert.expect(19);
this.router.map(function () {
this.route('thing', { path: '/thing/:thing_id' });
this.route('about');
});
this.addTemplate('index', '\n {{#link-to destinationRoute routeContext loadingClass=\'i-am-loading\' id=\'context-link\'}}\n string\n {{/link-to}}\n {{#link-to secondRoute loadingClass=loadingClass id=\'static-link\'}}\n string\n {{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
destinationRoute: null,
routeContext: null,
loadingClass: 'i-am-loading'
}));
this.add('route:about', _emberRouting.Route.extend({
activate: function () {
assert.ok(true, 'About was entered');
}
}));
this.visit('/');
function assertLinkStatus(link, url) {
if (url) {
assert.equal(normalizeUrl(link.attr('href')), url, 'loaded link-to has expected href');
assert.ok(!link.hasClass('i-am-loading'), 'loaded linkComponent has no loadingClass');
} else {
assert.equal(normalizeUrl(link.attr('href')), '#', "unloaded link-to has href='#'");
assert.ok(link.hasClass('i-am-loading'), 'loading linkComponent has loadingClass');
}
}
var contextLink = this.$('#context-link');
var staticLink = this.$('#static-link');
var controller = this.applicationInstance.lookup('controller:index');
assertLinkStatus(contextLink);
assertLinkStatus(staticLink);
this.warnCalled = false;
this.click(contextLink);
assert.ok(this.warnCalled, 'Logger.warn was called from clicking loading link');
// Set the destinationRoute (context is still null).
this.runTask(function () {
return controller.set('destinationRoute', 'thing');
});
assertLinkStatus(contextLink);
// Set the routeContext to an id
this.runTask(function () {
return controller.set('routeContext', '456');
});
assertLinkStatus(contextLink, '/thing/456');
// Test that 0 isn't interpreted as falsy.
this.runTask(function () {
return controller.set('routeContext', 0);
});
assertLinkStatus(contextLink, '/thing/0');
// Set the routeContext to an object
this.runTask(function () {
controller.set('routeContext', { id: 123 });
});
assertLinkStatus(contextLink, '/thing/123');
// Set the destinationRoute back to null.
this.runTask(function () {
return controller.set('destinationRoute', null);
});
assertLinkStatus(contextLink);
this.warnCalled = false;
this.click(staticLink);
assert.ok(this.warnCalled, 'Logger.warn was called from clicking loading link');
this.runTask(function () {
return controller.set('secondRoute', 'about');
});
assertLinkStatus(staticLink, '/about');
// Click the now-active link
this.click(staticLink);
};
return _class5;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper - globals mode app', function (_AutobootApplicationT) {
(0, _emberBabel.inherits)(_class6, _AutobootApplicationT);
function _class6() {
(0, _emberBabel.classCallCheck)(this, _class6);
return (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT.apply(this, arguments));
}
_class6.prototype['@test the {{link-to}} helper throws a useful error if you invoke it wrong'] = function (assert) {
var _this10 = this;
assert.expect(1);
assert.throws(function () {
_this10.runTask(function () {
_this10.createApplication();
_this10.add('router:main', _emberRouting.Router.extend({
location: 'none'
}));
_this10.router.map(function () {
this.route('post', { path: 'post/:post_id' });
});
_this10.addTemplate('application', '{{#link-to \'post\'}}Post{{/link-to}}');
});
}, /(You attempted to define a `\{\{link-to "post"\}\}` but did not pass the parameters required for generating its dynamic segments.|You must provide param `post_id` to `generate`)/);
};
return _class6;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
QUnit.module('ESLint | ember/tests/helpers/link_to_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/helpers/link_to_test.js should pass ESLint\n\n');
});
enifed('ember/tests/helpers/link_to_test/link_to_transitioning_classes_test', ['ember-babel', 'ember-runtime', 'ember-routing', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberRouting, _internalTestHelpers) {
'use strict';
function assertHasClass(assert, selector, label) {
var testLabel = selector.attr('id') + ' should have class ' + label;
assert.equal(selector.hasClass(label), true, testLabel);
}
function assertHasNoClass(assert, selector, label) {
var testLabel = selector.attr('id') + ' should not have class ' + label;
assert.equal(selector.hasClass(label), false, testLabel);
}
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper: .transitioning-in .transitioning-out CSS classes', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this2 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this));
_this2.aboutDefer = _emberRuntime.RSVP.defer();
_this2.otherDefer = _emberRuntime.RSVP.defer();
var _this = _this2;
_this2.router.map(function () {
this.route('about');
this.route('other');
});
_this2.add('route:about', _emberRouting.Route.extend({
model: function () {
return _this.aboutDefer.promise;
}
}));
_this2.add('route:other', _emberRouting.Route.extend({
model: function () {
return _this.otherDefer.promise;
}
}));
_this2.addTemplate('application', '\n {{outlet}}\n {{link-to \'Index\' \'index\' id=\'index-link\'}}\n {{link-to \'About\' \'about\' id=\'about-link\'}}\n {{link-to \'Other\' \'other\' id=\'other-link\'}}\n ');
_this2.visit('/');
return _this2;
}
_class.prototype.teardown = function teardown() {
_ApplicationTestCase.prototype.teardown.call(this);
this.aboutDefer = null;
this.otherDefer = null;
};
_class.prototype['@test while a transition is underway'] = function testWhileATransitionIsUnderway(assert) {
var _this3 = this;
var $index = this.$('#index-link');
var $about = this.$('#about-link');
var $other = this.$('#other-link');
$about.click();
assertHasClass(assert, $index, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
this.runTask(function () {
return _this3.aboutDefer.resolve();
});
assertHasNoClass(assert, $index, 'active');
assertHasClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper: .transitioning-in .transitioning-out CSS classes - nested link-to\'s', function (_ApplicationTestCase2) {
(0, _emberBabel.inherits)(_class2, _ApplicationTestCase2);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
var _this4 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase2.call(this));
_this4.aboutDefer = _emberRuntime.RSVP.defer();
_this4.otherDefer = _emberRuntime.RSVP.defer();
var _this = _this4;
_this4.router.map(function () {
this.route('parent-route', function () {
this.route('about');
this.route('other');
});
});
_this4.add('route:parent-route.about', _emberRouting.Route.extend({
model: function () {
return _this.aboutDefer.promise;
}
}));
_this4.add('route:parent-route.other', _emberRouting.Route.extend({
model: function () {
return _this.otherDefer.promise;
}
}));
_this4.addTemplate('application', '\n {{outlet}}\n {{#link-to \'index\' tagName=\'li\'}}\n {{link-to \'Index\' \'index\' id=\'index-link\'}}\n {{/link-to}}\n {{#link-to \'parent-route.about\' tagName=\'li\'}}\n {{link-to \'About\' \'parent-route.about\' id=\'about-link\'}}\n {{/link-to}}\n {{#link-to \'parent-route.other\' tagName=\'li\'}}\n {{link-to \'Other\' \'parent-route.other\' id=\'other-link\'}}\n {{/link-to}}\n ');
_this4.visit('/');
return _this4;
}
_class2.prototype.resolveAbout = function resolveAbout() {
var _this5 = this;
return this.runTask(function () {
_this5.aboutDefer.resolve();
_this5.aboutDefer = _emberRuntime.RSVP.defer();
});
};
_class2.prototype.resolveOther = function resolveOther() {
var _this6 = this;
return this.runTask(function () {
_this6.otherDefer.resolve();
_this6.otherDefer = _emberRuntime.RSVP.defer();
});
};
_class2.prototype.teardown = function teardown() {
_ApplicationTestCase2.prototype.teardown.call(this);
this.aboutDefer = null;
this.otherDefer = null;
};
_class2.prototype['@test while a transition is underway with nested link-to\'s'] = function (assert) {
var $index = this.$('#index-link');
var $about = this.$('#about-link');
var $other = this.$('#other-link');
$about.click();
assertHasClass(assert, $index, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
this.resolveAbout();
assertHasNoClass(assert, $index, 'active');
assertHasClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
$other.click();
assertHasNoClass(assert, $index, 'active');
assertHasClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
this.resolveOther();
assertHasNoClass(assert, $index, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
$about.click();
assertHasNoClass(assert, $index, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasClass(assert, $other, 'ember-transitioning-out');
this.resolveAbout();
assertHasNoClass(assert, $index, 'active');
assertHasClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
};
return _class2;
}(_internalTestHelpers.ApplicationTestCase));
});
QUnit.module('ESLint | ember/tests/helpers/link_to_test/link_to_transitioning_classes_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/helpers/link_to_test/link_to_transitioning_classes_test.js should pass ESLint\n\n');
});
enifed('ember/tests/helpers/link_to_test/link_to_with_query_params_test', ['ember-babel', 'ember-runtime', 'ember-routing', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberRouting, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper: invoking with query params', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this));
var indexProperties = {
foo: '123',
bar: 'abc'
};
_this.add('controller:index', _emberRuntime.Controller.extend({
queryParams: ['foo', 'bar', 'abool'],
foo: indexProperties.foo,
bar: indexProperties.bar,
boundThing: 'OMG',
abool: true
}));
_this.add('controller:about', _emberRuntime.Controller.extend({
queryParams: ['baz', 'bat'],
baz: 'alex',
bat: 'borf'
}));
_this.indexProperties = indexProperties;
return _this;
}
_class.prototype.shouldNotBeActive = function shouldNotBeActive(assert, selector) {
this.checkActive(assert, selector, false);
};
_class.prototype.shouldBeActive = function shouldBeActive(assert, selector) {
this.checkActive(assert, selector, true);
};
_class.prototype.getController = function getController(name) {
return this.applicationInstance.lookup('controller:' + name);
};
_class.prototype.checkActive = function checkActive(assert, selector, active) {
var classList = this.$(selector)[0].className;
assert.equal(classList.indexOf('active') > -1, active, selector + ' active should be ' + active.toString());
};
_class.prototype['@test doesn\'t update controller QP properties on current route when invoked'] = function (assert) {
var _this2 = this;
this.addTemplate('index', '\n {{#link-to \'index\' id=\'the-link\'}}Index{{/link-to}}\n ');
return this.visit('/').then(function () {
_this2.click('#the-link');
var indexController = _this2.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), _this2.indexProperties, 'controller QP properties do not update');
});
};
_class.prototype['@test doesn\'t update controller QP properties on current route when invoked (empty query-params obj)'] = function (assert) {
var _this3 = this;
this.addTemplate('index', '\n {{#link-to \'index\' (query-params) id=\'the-link\'}}Index{{/link-to}}\n ');
return this.visit('/').then(function () {
_this3.click('#the-link');
var indexController = _this3.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), _this3.indexProperties, 'controller QP properties do not update');
});
};
_class.prototype['@test doesn\'t update controller QP properties on current route when invoked (empty query-params obj, inferred route)'] = function (assert) {
var _this4 = this;
this.addTemplate('index', '\n {{#link-to (query-params) id=\'the-link\'}}Index{{/link-to}}\n ');
return this.visit('/').then(function () {
_this4.click('#the-link');
var indexController = _this4.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), _this4.indexProperties, 'controller QP properties do not update');
});
};
_class.prototype['@test updates controller QP properties on current route when invoked'] = function testUpdatesControllerQPPropertiesOnCurrentRouteWhenInvoked(assert) {
var _this5 = this;
this.addTemplate('index', '\n {{#link-to \'index\' (query-params foo=\'456\') id="the-link"}}\n Index\n {{/link-to}}\n ');
return this.visit('/').then(function () {
_this5.click('#the-link');
var indexController = _this5.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), { foo: '456', bar: 'abc' }, 'controller QP properties updated');
});
};
_class.prototype['@test updates controller QP properties on current route when invoked (inferred route)'] = function testUpdatesControllerQPPropertiesOnCurrentRouteWhenInvokedInferredRoute(assert) {
var _this6 = this;
this.addTemplate('index', '\n {{#link-to (query-params foo=\'456\') id="the-link"}}\n Index\n {{/link-to}}\n ');
return this.visit('/').then(function () {
_this6.click('#the-link');
var indexController = _this6.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), { foo: '456', bar: 'abc' }, 'controller QP properties updated');
});
};
_class.prototype['@test updates controller QP properties on other route after transitioning to that route'] = function testUpdatesControllerQPPropertiesOnOtherRouteAfterTransitioningToThatRoute(assert) {
var _this7 = this;
this.router.map(function () {
this.route('about');
});
this.addTemplate('index', '\n {{#link-to \'about\' (query-params baz=\'lol\') id=\'the-link\'}}\n About\n {{/link-to}}\n ');
return this.visit('/').then(function () {
var theLink = _this7.$('#the-link');
assert.equal(theLink.attr('href'), '/about?baz=lol');
_this7.runTask(function () {
return _this7.click('#the-link');
});
var aboutController = _this7.getController('about');
assert.deepEqual(aboutController.getProperties('baz', 'bat'), { baz: 'lol', bat: 'borf' }, 'about controller QP properties updated');
});
};
_class.prototype['@test supplied QP properties can be bound'] = function testSuppliedQPPropertiesCanBeBound(assert) {
var _this8 = this;
this.addTemplate('index', '\n {{#link-to (query-params foo=boundThing) id=\'the-link\'}}Index{{/link-to}}\n ');
return this.visit('/').then(function () {
var indexController = _this8.getController('index');
var theLink = _this8.$('#the-link');
assert.equal(theLink.attr('href'), '/?foo=OMG');
_this8.runTask(function () {
return indexController.set('boundThing', 'ASL');
});
assert.equal(theLink.attr('href'), '/?foo=ASL');
});
};
_class.prototype['@test supplied QP properties can be bound (booleans)'] = function testSuppliedQPPropertiesCanBeBoundBooleans(assert) {
var _this9 = this;
this.addTemplate('index', '\n {{#link-to (query-params abool=boundThing) id=\'the-link\'}}\n Index\n {{/link-to}}\n ');
return this.visit('/').then(function () {
var indexController = _this9.getController('index');
var theLink = _this9.$('#the-link');
assert.equal(theLink.attr('href'), '/?abool=OMG');
_this9.runTask(function () {
return indexController.set('boundThing', false);
});
assert.equal(theLink.attr('href'), '/?abool=false');
_this9.click('#the-link');
assert.deepEqual(indexController.getProperties('foo', 'bar', 'abool'), { foo: '123', bar: 'abc', abool: false }, 'bound bool QP properties update');
});
};
_class.prototype['@test href updates when unsupplied controller QP props change'] = function testHrefUpdatesWhenUnsuppliedControllerQPPropsChange(assert) {
var _this10 = this;
this.addTemplate('index', '\n {{#link-to (query-params foo=\'lol\') id=\'the-link\'}}Index{{/link-to}}\n ');
return this.visit('/').then(function () {
var indexController = _this10.getController('index');
var theLink = _this10.$('#the-link');
assert.equal(theLink.attr('href'), '/?foo=lol');
_this10.runTask(function () {
return indexController.set('bar', 'BORF');
});
assert.equal(theLink.attr('href'), '/?bar=BORF&foo=lol');
_this10.runTask(function () {
return indexController.set('foo', 'YEAH');
});
assert.equal(theLink.attr('href'), '/?bar=BORF&foo=lol');
});
};
_class.prototype['@test The {{link-to}} with only query params always transitions to the current route with the query params applied'] = function testTheLinkToWithOnlyQueryParamsAlwaysTransitionsToTheCurrentRouteWithTheQueryParamsApplied(assert) {
var _this11 = this;
// Test harness for bug #12033
this.addTemplate('cars', '\n {{#link-to \'cars.create\' id=\'create-link\'}}Create new car{{/link-to}}\n {{#link-to (query-params page=\'2\') id=\'page2-link\'}}Page 2{{/link-to}}\n {{outlet}}\n ');
this.addTemplate('cars.create', '{{#link-to \'cars\' id=\'close-link\'}}Close create form{{/link-to}}');
this.router.map(function () {
this.route('cars', function () {
this.route('create');
});
});
this.add('controller:cars', _emberRuntime.Controller.extend({
queryParams: ['page'],
page: 1
}));
return this.visit('/cars/create').then(function () {
var router = _this11.appRouter;
var carsController = _this11.getController('cars');
assert.equal(router.currentRouteName, 'cars.create');
_this11.runTask(function () {
return _this11.click('#close-link');
});
assert.equal(router.currentRouteName, 'cars.index');
assert.equal(router.get('url'), '/cars');
assert.equal(carsController.get('page'), 1, 'The page query-param is 1');
_this11.runTask(function () {
return _this11.click('#page2-link');
});
assert.equal(router.currentRouteName, 'cars.index', 'The active route is still cars');
assert.equal(router.get('url'), '/cars?page=2', 'The url has been updated');
assert.equal(carsController.get('page'), 2, 'The query params have been updated');
});
};
_class.prototype['@test the {{link-to}} applies activeClass when query params are not changed'] = function testTheLinkToAppliesActiveClassWhenQueryParamsAreNotChanged(assert) {
var _this12 = this;
this.addTemplate('index', '\n {{#link-to (query-params foo=\'cat\') id=\'cat-link\'}}Index{{/link-to}}\n {{#link-to (query-params foo=\'dog\') id=\'dog-link\'}}Index{{/link-to}}\n {{#link-to \'index\' id=\'change-nothing\'}}Index{{/link-to}}\n ');
this.addTemplate('search', '\n {{#link-to (query-params search=\'same\') id=\'same-search\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'change\') id=\'change-search\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'same\' archive=true) id=\'same-search-add-archive\'}}Index{{/link-to}}\n {{#link-to (query-params archive=true) id=\'only-add-archive\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'same\' archive=true) id=\'both-same\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'different\' archive=true) id=\'change-one\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'different\' archive=false) id=\'remove-one\'}}Index{{/link-to}}\n {{outlet}}\n ');
this.addTemplate('search.results', '\n {{#link-to (query-params sort=\'title\') id=\'same-sort-child-only\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'same\') id=\'same-search-parent-only\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'change\') id=\'change-search-parent-only\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'same\' sort=\'title\') id=\'same-search-same-sort-child-and-parent\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'same\' sort=\'author\') id=\'same-search-different-sort-child-and-parent\'}}Index{{/link-to}}\n {{#link-to (query-params search=\'change\' sort=\'title\') id=\'change-search-same-sort-child-and-parent\'}}Index{{/link-to}}\n {{#link-to (query-params foo=\'dog\') id=\'dog-link\'}}Index{{/link-to}}\n ');
this.router.map(function () {
this.route('search', function () {
this.route('results');
});
});
this.add('controller:search', _emberRuntime.Controller.extend({
queryParams: ['search', 'archive'],
search: '',
archive: false
}));
this.add('controller:search.results', _emberRuntime.Controller.extend({
queryParams: ['sort', 'showDetails'],
sort: 'title',
showDetails: true
}));
return this.visit('/').then(function () {
_this12.shouldNotBeActive(assert, '#cat-link');
_this12.shouldNotBeActive(assert, '#dog-link');
return _this12.visit('/?foo=cat');
}).then(function () {
_this12.shouldBeActive(assert, '#cat-link');
_this12.shouldNotBeActive(assert, '#dog-link');
return _this12.visit('/?foo=dog');
}).then(function () {
_this12.shouldBeActive(assert, '#dog-link');
_this12.shouldNotBeActive(assert, '#cat-link');
_this12.shouldBeActive(assert, '#change-nothing');
return _this12.visit('/search?search=same');
}).then(function () {
_this12.shouldBeActive(assert, '#same-search');
_this12.shouldNotBeActive(assert, '#change-search');
_this12.shouldNotBeActive(assert, '#same-search-add-archive');
_this12.shouldNotBeActive(assert, '#only-add-archive');
_this12.shouldNotBeActive(assert, '#remove-one');
return _this12.visit('/search?search=same&archive=true');
}).then(function () {
_this12.shouldBeActive(assert, '#both-same');
_this12.shouldNotBeActive(assert, '#change-one');
return _this12.visit('/search/results?search=same&sort=title&showDetails=true');
}).then(function () {
_this12.shouldBeActive(assert, '#same-sort-child-only');
_this12.shouldBeActive(assert, '#same-search-parent-only');
_this12.shouldNotBeActive(assert, '#change-search-parent-only');
_this12.shouldBeActive(assert, '#same-search-same-sort-child-and-parent');
_this12.shouldNotBeActive(assert, '#same-search-different-sort-child-and-parent');
_this12.shouldNotBeActive(assert, '#change-search-same-sort-child-and-parent');
});
};
_class.prototype['@test the {{link-to}} applies active class when query-param is a number'] = function testTheLinkToAppliesActiveClassWhenQueryParamIsANumber(assert) {
var _this13 = this;
this.addTemplate('index', '\n {{#link-to (query-params page=pageNumber) id=\'page-link\'}}\n Index\n {{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
queryParams: ['page'],
page: 1,
pageNumber: 5
}));
return this.visit('/').then(function () {
_this13.shouldNotBeActive(assert, '#page-link');
return _this13.visit('/?page=5');
}).then(function () {
_this13.shouldBeActive(assert, '#page-link');
});
};
_class.prototype['@test the {{link-to}} applies active class when query-param is an array'] = function testTheLinkToAppliesActiveClassWhenQueryParamIsAnArray(assert) {
var _this14 = this;
this.addTemplate('index', '\n {{#link-to (query-params pages=pagesArray) id=\'array-link\'}}Index{{/link-to}}\n {{#link-to (query-params pages=biggerArray) id=\'bigger-link\'}}Index{{/link-to}}\n {{#link-to (query-params pages=emptyArray) id=\'empty-link\'}}Index{{/link-to}}\n ');
this.add('controller:index', _emberRuntime.Controller.extend({
queryParams: ['pages'],
pages: [],
pagesArray: [1, 2],
biggerArray: [1, 2, 3],
emptyArray: []
}));
return this.visit('/').then(function () {
_this14.shouldNotBeActive(assert, '#array-link');
return _this14.visit('/?pages=%5B1%2C2%5D');
}).then(function () {
_this14.shouldBeActive(assert, '#array-link');
_this14.shouldNotBeActive(assert, '#bigger-link');
_this14.shouldNotBeActive(assert, '#empty-link');
return _this14.visit('/?pages=%5B2%2C1%5D');
}).then(function () {
_this14.shouldNotBeActive(assert, '#array-link');
_this14.shouldNotBeActive(assert, '#bigger-link');
_this14.shouldNotBeActive(assert, '#empty-link');
return _this14.visit('/?pages=%5B1%2C2%2C3%5D');
}).then(function () {
_this14.shouldBeActive(assert, '#bigger-link');
_this14.shouldNotBeActive(assert, '#array-link');
_this14.shouldNotBeActive(assert, '#empty-link');
});
};
_class.prototype['@test the {{link-to}} helper applies active class to the parent route'] = function testTheLinkToHelperAppliesActiveClassToTheParentRoute(assert) {
var _this15 = this;
this.router.map(function () {
this.route('parent', function () {
this.route('child');
});
});
this.addTemplate('application', '\n {{#link-to \'parent\' id=\'parent-link\'}}Parent{{/link-to}}\n {{#link-to \'parent.child\' id=\'parent-child-link\'}}Child{{/link-to}}\n {{#link-to \'parent\' (query-params foo=cat) id=\'parent-link-qp\'}}Parent{{/link-to}}\n {{outlet}}\n ');
this.add('controller:parent.child', _emberRuntime.Controller.extend({
queryParams: ['foo'],
foo: 'bar'
}));
return this.visit('/').then(function () {
_this15.shouldNotBeActive(assert, '#parent-link');
_this15.shouldNotBeActive(assert, '#parent-child-link');
_this15.shouldNotBeActive(assert, '#parent-link-qp');
return _this15.visit('/parent/child?foo=dog');
}).then(function () {
_this15.shouldBeActive(assert, '#parent-link');
_this15.shouldNotBeActive(assert, '#parent-link-qp');
});
};
_class.prototype['@test The {{link-to}} helper disregards query-params in activeness computation when current-when is specified'] = function testTheLinkToHelperDisregardsQueryParamsInActivenessComputationWhenCurrentWhenIsSpecified(assert) {
var _this16 = this;
var appLink = void 0;
this.router.map(function () {
this.route('parent');
});
this.addTemplate('application', '\n {{#link-to \'parent\' (query-params page=1) current-when=\'parent\' id=\'app-link\'}}\n Parent\n {{/link-to}}\n {{outlet}}\n ');
this.addTemplate('parent', '\n {{#link-to \'parent\' (query-params page=1) current-when=\'parent\' id=\'parent-link\'}}\n Parent\n {{/link-to}}\n {{outlet}}\n ');
this.add('controller:parent', _emberRuntime.Controller.extend({
queryParams: ['page'],
page: 1
}));
return this.visit('/').then(function () {
appLink = _this16.$('#app-link');
assert.equal(appLink.attr('href'), '/parent');
_this16.shouldNotBeActive(assert, '#app-link');
return _this16.visit('/parent?page=2');
}).then(function () {
appLink = _this16.$('#app-link');
var router = _this16.appRouter;
assert.equal(appLink.attr('href'), '/parent');
_this16.shouldBeActive(assert, '#app-link');
assert.equal(_this16.$('#parent-link').attr('href'), '/parent');
_this16.shouldBeActive(assert, '#parent-link');
var parentController = _this16.getController('parent');
assert.equal(parentController.get('page'), 2);
_this16.runTask(function () {
return parentController.set('page', 3);
});
assert.equal(router.get('location.path'), '/parent?page=3');
_this16.shouldBeActive(assert, '#app-link');
_this16.shouldBeActive(assert, '#parent-link');
_this16.runTask(function () {
return _this16.click('#app-link');
});
assert.equal(router.get('location.path'), '/parent');
});
};
_class.prototype['@test link-to default query params while in active transition regression test'] = function testLinkToDefaultQueryParamsWhileInActiveTransitionRegressionTest(assert) {
var _this17 = this;
this.router.map(function () {
this.route('foos');
this.route('bars');
});
var foos = _emberRuntime.RSVP.defer();
var bars = _emberRuntime.RSVP.defer();
this.addTemplate('application', '\n {{link-to \'Foos\' \'foos\' id=\'foos-link\'}}\n {{link-to \'Baz Foos\' \'foos\' (query-params baz=true) id=\'baz-foos-link\'}}\n {{link-to \'Quux Bars\' \'bars\' (query-params quux=true) id=\'bars-link\'}}\n ');
this.add('controller:foos', _emberRuntime.Controller.extend({
queryParams: ['status'],
baz: false
}));
this.add('route:foos', _emberRouting.Route.extend({
model: function () {
return foos.promise;
}
}));
this.add('controller:bars', _emberRuntime.Controller.extend({
queryParams: ['status'],
quux: false
}));
this.add('route:bars', _emberRouting.Route.extend({
model: function () {
return bars.promise;
}
}));
return this.visit('/').then(function () {
var router = _this17.appRouter;
var foosLink = _this17.$('#foos-link');
var barsLink = _this17.$('#bars-link');
var bazLink = _this17.$('#baz-foos-link');
assert.equal(foosLink.attr('href'), '/foos');
assert.equal(bazLink.attr('href'), '/foos?baz=true');
assert.equal(barsLink.attr('href'), '/bars?quux=true');
assert.equal(router.get('location.path'), '/');
_this17.shouldNotBeActive(assert, '#foos-link');
_this17.shouldNotBeActive(assert, '#baz-foos-link');
_this17.shouldNotBeActive(assert, '#bars-link');
_this17.runTask(function () {
return barsLink.click();
});
_this17.shouldNotBeActive(assert, '#bars-link');
_this17.runTask(function () {
return foosLink.click();
});
_this17.shouldNotBeActive(assert, '#foos-link');
_this17.runTask(function () {
return foos.resolve();
});
assert.equal(router.get('location.path'), '/foos');
_this17.shouldBeActive(assert, '#foos-link');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper + query params - globals mode app', function (_AutobootApplicationT) {
(0, _emberBabel.inherits)(_class2, _AutobootApplicationT);
function _class2() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT.apply(this, arguments));
}
_class2.prototype['@test the {{link-to}} helper throws a useful error if you invoke it wrong'] = function (assert) {
var _this19 = this;
assert.expect(1);
expectAssertion(function () {
_this19.runTask(function () {
_this19.createApplication();
_this19.add('router:main', _emberRouting.Router.extend({
location: 'none'
}));
_this19.addTemplate('application', '{{#link-to id=\'the-link\'}}Index{{/link-to}}');
});
}, /You must provide one or more parameters to the link-to component/);
};
return _class2;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
QUnit.module('ESLint | ember/tests/helpers/link_to_test/link_to_with_query_params_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/helpers/link_to_test/link_to_with_query_params_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Render index template into application outlet'] = function testRenderIndexTemplateIntoApplicationOutlet(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));
});
QUnit.module('ESLint | ember/tests/homepage_example_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/homepage_example_test.js should pass ESLint\n\n');
});
enifed('ember/tests/integration/multiple-app-test', ['ember-babel', 'internal-test-helpers', 'ember-application', 'ember-glimmer', 'ember-views', 'ember-utils'], function (_emberBabel, _internalTestHelpers, _emberApplication, _emberGlimmer, _emberViews, _emberUtils) {
'use strict';
(0, _internalTestHelpers.moduleFor)('View Integration', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
(0, _emberViews.jQuery)('#qunit-fixture').html('\n
\n
\n ');
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this));
_this.runTask(function () {
_this.createSecondApplication();
});
return _this;
}
_class.prototype.createSecondApplication = function createSecondApplication(options) {
var applicationOptions = this.applicationOptions;
var secondApplicationOptions = { rootElement: '#two' };
var myOptions = (0, _emberUtils.assign)(applicationOptions, secondApplicationOptions, options);
this.secondApp = _emberApplication.Application.create(myOptions);
this.secondResolver = myOptions.Resolver.lastInstance;
return this.secondApp;
};
_class.prototype.teardown = function teardown() {
var _this2 = this;
_ApplicationTestCase.prototype.teardown.call(this);
if (this.secondApp) {
this.runTask(function () {
_this2.secondApp.destroy();
});
}
};
_class.prototype.addFactoriesToResolver = function addFactoriesToResolver(actions, resolver) {
resolver.add('component:special-button', _emberGlimmer.Component.extend({
actions: {
doStuff: function () {
var rootElement = (0, _emberUtils.getOwner)(this).application.rootElement;
actions.push(rootElement);
}
}
}));
resolver.add('template:index', this.compile('\n Node 1 {{special-button}}\n ', {
moduleName: 'index'
}));
resolver.add('template:components/special-button', this.compile('\n Button \n ', {
moduleName: 'components/special-button'
}));
};
_class.prototype['@test booting multiple applications can properly handle events'] = function (assert) {
var _this3 = this;
var actions = [];
this.addFactoriesToResolver(actions, this.resolver);
this.addFactoriesToResolver(actions, this.secondResolver);
this.runTask(function () {
_this3.secondApp.visit('/');
});
this.runTask(function () {
_this3.application.visit('/');
});
(0, _emberViews.jQuery)('#two .do-stuff').click();
(0, _emberViews.jQuery)('#one .do-stuff').click();
assert.deepEqual(actions, ['#two', '#one']);
};
(0, _emberBabel.createClass)(_class, [{
key: 'applicationOptions',
get: function () {
return (0, _emberUtils.assign)(_ApplicationTestCase.prototype.applicationOptions, {
rootElement: '#one',
router: null
});
}
}]);
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
QUnit.module('ESLint | ember/tests/integration/multiple-app-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/integration/multiple-app-test.js should pass ESLint\n\n');
});
enifed('ember/tests/production_build_test', ['ember-debug'], function (_emberDebug) {
'use strict';
QUnit.module('production builds');
if (!true) {
QUnit.test('assert does not throw in production builds', function (assert) {
assert.expect(1);
try {
(true && !(false) && (0, _emberDebug.assert)('Should not throw'));
assert.ok(true, 'Ember.assert did not throw');
} catch (e) {
assert.ok(false, 'Expected assert not to throw but it did: ' + e.message);
}
});
QUnit.test('runInDebug does not run the callback in production builds', function (assert) {
var fired = false;
(0, _emberDebug.runInDebug)(function () {
return fired = true;
});
assert.equal(fired, false, 'runInDebug callback should not be ran');
});
}
});
QUnit.module('ESLint | ember/tests/production_build_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/production_build_test.js should pass ESLint\n\n');
});
enifed('ember/tests/reexports_test', ['ember/index', 'internal-test-helpers', 'ember/features'], function (_index, _internalTestHelpers, _features) {
'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-debug
['deprecateFunc', 'ember-debug'], ['deprecate', 'ember-debug'], ['assert', 'ember-debug'], ['warn', 'ember-debug'], ['debug', 'ember-debug'], ['runInDebug', 'ember-debug'],
// ember-metal
['computed', 'ember-metal'], ['computed.alias', 'ember-metal', 'alias'], ['ComputedProperty', 'ember-metal'], ['cacheFor', 'ember-metal'], ['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');
});
if (_features.EMBER_METAL_WEAKMAP) {
QUnit.test('Ember.WeakMap exports correctly', function (assert) {
(0, _internalTestHelpers.confirmExport)(_index.default, assert, 'WeakMap', 'ember-metal', 'WeakMap');
});
}
if (true) {
QUnit.test('Ember.MODEL_FACTORY_INJECTIONS', function (assert) {
var descriptor = Object.getOwnPropertyDescriptor(_index.default, 'MODEL_FACTORY_INJECTIONS');
assert.equal(descriptor.enumerable, false, 'descriptor is not enumerable');
assert.equal(descriptor.configurable, false, 'descriptor is not configurable');
assert.equal(_index.default.MODEL_FACTORY_INJECTIONS, false);
expectDeprecation(function () {
_index.default.MODEL_FACTORY_INJECTIONS = true;
}, 'Ember.MODEL_FACTORY_INJECTIONS is no longer required');
assert.equal(_index.default.MODEL_FACTORY_INJECTIONS, false, 'writing to the property has no affect');
});
}
});
QUnit.module('ESLint | ember/tests/reexports_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/reexports_test.js should pass ESLint\n\n');
});
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 (value) {
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 (value) {
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 (controller) {
// 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 (controller) {
(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 (result) {
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 (result) {
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 (obj) {
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 (context) {
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: '/' });
});
});
var model1 = { name: 'Tilde' };
var model2 = { name: 'Tom Dale' };
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: model1,
model2: model2
});
(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 post1 = {};
var post2 = {};
var post3 = {};
var share1 = {};
var share2 = {};
var share3 = {};
var posts = {
1: post1,
2: post2,
3: post3
};
var shares = {
1: share1,
2: share2,
3: share3
};
App.ThePostRoute = _emberRouting.Route.extend({
model: function (params) {
return posts[params.post_id];
}
});
App.ThePostCommentsRoute = _emberRouting.Route.extend({
afterModel: function (post, transition) {
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, transition) {
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 post1 = {};
var post2 = {};
var post3 = {};
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({
afterModel: function (post, transition) {
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 (context) {
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 (context) {
this.transitionTo('post.edit');
}
}
});
App.PostEditRoute = _emberRouting.Route.extend({
model: function (params) {
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 overridden 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 (controller) {
this.controllerFor('shared').set('message', 'This is the ' + this.routeName + ' message');
},
renderTemplate: function (controller, context) {
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 (value) {
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 () {
var _this = this;
expectAssertion(function () {
_this.render('homepage', { controller: 'stefanpenneristhemanforme' });
}, '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' });
}
});
bootApplication();
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 (controller, model, transition) {
calls.push(['setup', this.routeName]);
},
resetController: function (controller) {
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 (assert) {
App.ApplicationRoute = _emberRouting.Route.extend({
actions: {
showModal: function () {
this.render({
outlet: undefined,
parentView: 'application'
});
},
hideModal: function () {
this.disconnectOutlet({
outlet: undefined,
parentView: 'application'
});
}
}
});
bootApplication();
expectAssertion(function () {
(0, _emberMetal.run)(function () {
return router.send('showModal');
});
}, /You passed undefined as the outlet name/);
expectAssertion(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
};
};
var BlogMap = function () {
this.route('post', { path: '/post/:post_id', serialize: postSerialize });
};
registry.register('route-map:blog', BlogMap);
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
var BlogMap = function () {
this.route('post');
};
registry.register('route-map:blog', BlogMap);
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
var BlogMap = function () {
this.route('post');
};
registry.register('route-map:blog', BlogMap);
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');
});
});
QUnit.module('ESLint | ember/tests/routing/basic_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/basic_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype.refreshModelWhileLoadingTest = function refreshModelWhileLoadingTest(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 (params) {
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;
return;
});
} 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 testNoReplaceURLOccursOnStartupBecauseDefaultValuesDonTShowUpInURL(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 testCallingTransitionToDoesNotLoseQueryParamsAlreadyOnTheActiveTransition(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 testSingleQueryParamsCanBeSetOnTheControllerAndReflectedInTheUrl(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 testQueryParamsCanMapToDifferentUrlKeysConfiguredOnTheController(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 testRoutesHaveAPrivateOverridableSerializeQueryParamKeyHook(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 testCanOverrideInheritedQPBehaviorBySpecifyingQueryParamsAsAComputedProperty(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 overridden param');
});
};
_class.prototype['@test Can concatenate inherited QP behavior by specifying queryParams as an array'] = function testCanConcatenateInheritedQPBehaviorBySpecifyingQueryParamsAsAnArray(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 testModelHooksReceivesQueryParams(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 testModelHooksReceivesQueryParamsWithDynamicSegmentParams(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 testModelHooksReceivesQueryParamsOverriddenByIncomingUrlValue(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 testErrorIsThrownIfDynamicSegmentAndQueryParamHaveSameName(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 testQueryParamsHaveBeenSetByTheTimeSetupControllerIsCalled(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 testMappedQueryParamsHaveBeenSetByTheTimeSetupControllerIsCalled(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 testRouteParamsForFetchesQueryParamsWithDefaultValue(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 (params, transition) {
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 testRouteParamsForFetchesQueryParamsWithNonDefaultValue(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 (params, transition) {
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 testRouteParamsForFetchesDefaultFalsyQueryParams(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 (params, transition) {
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 testRouteParamsForFetchesNonDefaultFalsyQueryParams(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 (params, transition) {
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 testModelHookCanQueryPrefixLessApplicationParams(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 testModelHookCanQueryPrefixLessApplicationParamsOverriddenByIncomingUrlValue(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 testCanOptIntoFullTransitionBySettingRefreshModelInRouteQueryParams(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 (params) {
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 testRefreshModelAndReplaceWorkTogether(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 (params) {
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 testMultipleQPValueChangesOnlyCauseASingleModelRefresh(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 testRefreshModelDoesNotCauseASecondTransitionDuringAppBoot(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 testQueryParamsAreUpdatedWhenAControllerPropertyIsSetAndTheRouteIsRefreshedIssue13263(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 testUseEmberGetToRetrieveQueryParamsRefreshModelConfiguration(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 (params) {
appModelCount++;
}
}));
var indexModelCount = 0;
this.add('route:index', _emberRouting.Route.extend({
queryParams: _emberRuntime.Object.create({
unknownProperty: function (keyName) {
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 testCanUseRefreshModelEvenWithURLChangesThatRemoveQPsFromAddressBar(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 testCanOptIntoAReplaceQueryBySpecifyingReplaceTrueInTheRouteConfigHash(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 testRouteQueryParamsConfigCanBeConfiguredUsingPropertyNameInsteadOfURLKey(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 testAnExplicitReplaceFalseOnAChangedQPAlwaysWinsAndCausesAPushState(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 testCanOptIntoFullTransitionBySettingRefreshModelInRouteQueryParamsWhenTransitioningFromChildToParent(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 testUseEmberGetToRetrieveQueryParamsReplaceConfiguration(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 (keyName) {
// 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 testCanOverrideIncomingQPValuesInSetupController(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 testCanOverrideIncomingQPArrayValuesInSetupController(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 testURLTransitionsThatRemoveQPsStillRegisterAsQPChanges(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 testSubresourceNamingStyleIsSupported(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 testTransitionToSupportsQueryParams(assert) {
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 testTransitionToSupportsQueryParamsMultiple(assert) {
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 testSettingControllerQPToEmptyStringDoesnTGenerateNullInURL(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 testSettingQPToEmptyStringDoesnTGenerateNullInURL(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 testADefaultBooleanValueDeserializesQPsAsBooleansRatherThanStrings(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 testQueryParamWithoutValueAreEmptyString(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 testArrayQueryParamsCanBeSet(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 testDeSerializationArrays(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 testUrlWithArrayQueryParamSetsControllerPropertyToArray(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 testArrayQueryParamsCanBePushedPopped(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 testOverwritingWithArrayWithSameContentShouldnTRefireUpdate(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 testDefaultingToParamsHashAsTheModelShouldNotResultInThatParamsObjectBeingWatched(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.peekMeta)(trans.params.application);
assert.ok(m === undefined, '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 testAChildOfAResourceRouteStillDefaultsToParentRouteSModelEvenIfTheChildRouteHasAQueryParam(assert) {
assert.expect(2);
this.setSingleQPController('index', 'woot', undefined, {
woot: undefined
});
this.add('route:application', _emberRouting.Route.extend({
model: function (p, trans) {
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 testOptingIntoReplaceDoesNotAffectTransitionsBetweenRoutes(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 testUndefinedIsnTSerializedOrDeserializedIntoAString(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 testWhenRefreshModelIsTrueAndLoadingHookIsUndefinedModelHookWillRerunWhenQPsChangeEvenIfPreviousDidNotFinish(assert) {
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 testWhenRefreshModelIsTrueAndLoadingHookReturnsFalseModelHookWillRerunWhenQPsChangeEvenIfPreviousDidNotFinish(assert) {
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 testWhenRefreshModelIsTrueAndLoadingHookReturnsTrueModelHookWillRerunWhenQPsChangeEvenIfPreviousDidNotFinish(assert) {
return this.refreshModelWhileLoadingTest(true);
};
_class.prototype['@test warn user that Route\'s queryParams configuration must be an Object, not an Array'] = function testWarnUserThatRouteSQueryParamsConfigurationMustBeAnObjectNotAnArray(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 testHandleRouteNamesThatClashWithObjectPrototypeProperties(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));
});
QUnit.module('ESLint | ember/tests/routing/query_params_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/query_params_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, ModelDependentQPTestCase);
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
ModelDependentQPTestCase.prototype.boot = function boot() {
this.setupApplication();
return this.visitApplication();
};
ModelDependentQPTestCase.prototype.teardown = function teardown() {
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 reopenController(name, options) {
this.application.resolveRegistration('controller:' + name).reopen(options);
};
ModelDependentQPTestCase.prototype.reopenRoute = function reopenRoute(name, options) {
this.application.resolveRegistration('route:' + name).reopen(options);
};
ModelDependentQPTestCase.prototype.queryParamsStickyTest1 = function queryParamsStickyTest1(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 queryParamsStickyTest2(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 queryParamsStickyTest3(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 queryParamsStickyTest4(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 queryParamsStickyTest5(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 queryParamsStickyTest6(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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest.apply(this, arguments));
}
_class.prototype.setupApplication = function setupApplication() {
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 visitApplication() {
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 testQueryParamsHaveModelStickinessByDefault() {
return this.queryParamsStickyTest1('/a');
};
_class.prototype['@test query params have \'model\' stickiness by default (url changes)'] = function testQueryParamsHaveModelStickinessByDefaultUrlChanges() {
return this.queryParamsStickyTest2('/a');
};
_class.prototype['@test query params have \'model\' stickiness by default (params-based transitions)'] = function testQueryParamsHaveModelStickinessByDefaultParamsBasedTransitions() {
return this.queryParamsStickyTest3('/a', 'article');
};
_class.prototype['@test \'controller\' stickiness shares QP state between models'] = function testControllerStickinessSharesQPStateBetweenModels() {
return this.queryParamsStickyTest4('/a', 'article');
};
_class.prototype['@test \'model\' stickiness is scoped to current or first dynamic parent route'] = function testModelStickinessIsScopedToCurrentOrFirstDynamicParentRoute() {
return this.queryParamsStickyTest5('/a', 'comments');
};
_class.prototype['@test can reset query params using the resetController hook'] = function testCanResetQueryParamsUsingTheResetControllerHook() {
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() {
(0, _emberBabel.classCallCheck)(this, _class2);
return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest2.apply(this, arguments));
}
_class2.prototype.setupApplication = function setupApplication() {
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 visitApplication() {
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 testQueryParamsHaveModelStickinessByDefault() {
return this.queryParamsStickyTest1('/site/a');
};
_class2.prototype['@test query params have \'model\' stickiness by default (url changes)'] = function testQueryParamsHaveModelStickinessByDefaultUrlChanges() {
return this.queryParamsStickyTest2('/site/a');
};
_class2.prototype['@test query params have \'model\' stickiness by default (params-based transitions)'] = function testQueryParamsHaveModelStickinessByDefaultParamsBasedTransitions() {
return this.queryParamsStickyTest3('/site/a', 'site.article');
};
_class2.prototype['@test \'controller\' stickiness shares QP state between models'] = function testControllerStickinessSharesQPStateBetweenModels() {
return this.queryParamsStickyTest4('/site/a', 'site.article');
};
_class2.prototype['@test \'model\' stickiness is scoped to current or first dynamic parent route'] = function testModelStickinessIsScopedToCurrentOrFirstDynamicParentRoute() {
return this.queryParamsStickyTest5('/site/a', 'site.article.comments');
};
_class2.prototype['@test can reset query params using the resetController hook'] = function testCanResetQueryParamsUsingTheResetControllerHook() {
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() {
(0, _emberBabel.classCallCheck)(this, _class3);
return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest3.apply(this, arguments));
}
_class3.prototype.setupApplication = function setupApplication() {
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 visitApplication() {
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 testQueryParamsHaveModelStickinessByDefault(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 testQueryParamsHaveModelStickinessByDefaultUrlChanges(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 testQueryParamsHaveModelStickinessByDefaultParamsBasedTransitions(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));
});
QUnit.module('ESLint | ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype.setupBase = function setupBase() {
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 testCanRemapSameNamedQpProps(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 testQueryParamsCanBeEitherControllerPropertyOrUrlKey(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 testQueryParamMatchingAUrlKeyAndControllerProperty(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 testQueryParamMatchingSamePropertyOnTwoControllersUseTheUrlKeyHigherInTheChain(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 testQueryParamsDoesNotErrorWhenAQueryParameterExistsForRouteInstancesThatShareAController(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 testQueryParamsInTheSameRouteHierarchyWithTheSameUrlKeyGetAutoScoped(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 testSupportSharedButOverridableMixinPattern(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));
});
QUnit.module('ESLint | ember/tests/routing/query_params_test/overlapping_query_params_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/query_params_test/overlapping_query_params_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _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 testCanRenderALinkToAnAsynchronouslyLoadedRouteWithoutFetchingTheRoute(assert) {
var _this2 = this;
assert.expect(4);
this.router.map(function () {
this.route('post', { path: '/post/:id' });
});
this.setSingleQPController('post');
var setupAppTemplate = 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 ');
};
setupAppTemplate();
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 testCanTransitionToToAnAsynchronouslyLoadedRouteWithSimpleQueryParams(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 testCanTransitionToToAnAsynchronouslyLoadedRouteWithArrayQueryParams(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 testCanTransitionToToAnAsynchronouslyLoadedRouteWithMappedQueryParams(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 testCanTransitionToWithAURL(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 testUndefinedIsnTSerializedOrDeserializedIntoAString(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));
});
QUnit.module('ESLint | ember/tests/routing/query_params_test/query_param_async_get_handler_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/query_params_test/query_param_async_get_handler_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype.testParamlessLinks = function testParamlessLinks(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 testParamLessLinksInAnAppBootedWithQueryParamsInTheURLDonTResetTheQueryParamsApplication(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 testParamLessLinksInAnAppBootedWithQueryParamsInTheURLDonTResetTheQueryParamsIndex(assert) {
return this.testParamlessLinks(assert, 'index');
};
return _class;
}(_internalTestHelpers.QueryParamTestCase));
});
QUnit.module('ESLint | ember/tests/routing/query_params_test/query_params_paramless_link_to_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/query_params_test/query_params_paramless_link_to_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype.boot = function boot() {
this.setupApplication();
return this.visitApplication();
};
_class.prototype.setupApplication = function setupApplication() {
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 visitApplication() {
return this.visit('/');
};
_class.prototype['@test can modify shared state before transition'] = function testCanModifySharedStateBeforeTransition(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 testCanModifySharedStateBackToTheDefaultValueBeforeTransition(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));
});
QUnit.module('ESLint | ember/tests/routing/query_params_test/shared_state_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/query_params_test/shared_state_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Router.map returns an Ember Router class'] = function testRouterMapReturnsAnEmberRouterClass(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 testRouterMapCanBeCalledMultipleTimes(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));
});
QUnit.module('ESLint | ember/tests/routing/router_map_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/router_map_test.js should pass ESLint\n\n');
});
enifed('ember/tests/routing/router_service_test/basic_test', ['ember-babel', 'ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers', 'ember/features'], function (_emberBabel, _emberRuntime, _emberGlimmer, _emberRouting, _emberMetal, _internalTestHelpers, _features) {
'use strict';
if (_features.EMBER_ROUTING_ROUTER_SERVICE) {
(0, _internalTestHelpers.moduleFor)('Router Service - main', function (_RouterTestCase) {
(0, _emberBabel.inherits)(_class, _RouterTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RouterTestCase.apply(this, arguments));
}
_class.prototype['@test RouterService#currentRouteName is correctly set for top level route'] = function testRouterServiceCurrentRouteNameIsCorrectlySetForTopLevelRoute(assert) {
var _this2 = this;
assert.expect(1);
return this.visit('/').then(function () {
assert.equal(_this2.routerService.get('currentRouteName'), 'parent.index');
});
};
_class.prototype['@test RouterService#currentRouteName is correctly set for child route'] = function testRouterServiceCurrentRouteNameIsCorrectlySetForChildRoute(assert) {
var _this3 = this;
assert.expect(1);
return this.visit('/child').then(function () {
assert.equal(_this3.routerService.get('currentRouteName'), 'parent.child');
});
};
_class.prototype['@test RouterService#currentRouteName is correctly set after transition'] = function testRouterServiceCurrentRouteNameIsCorrectlySetAfterTransition(assert) {
var _this4 = this;
assert.expect(1);
return this.visit('/child').then(function () {
return _this4.routerService.transitionTo('parent.sister');
}).then(function () {
assert.equal(_this4.routerService.get('currentRouteName'), 'parent.sister');
});
};
_class.prototype['@test RouterService#currentRouteName is correctly set on each transition'] = function testRouterServiceCurrentRouteNameIsCorrectlySetOnEachTransition(assert) {
var _this5 = this;
assert.expect(3);
return this.visit('/child').then(function () {
assert.equal(_this5.routerService.get('currentRouteName'), 'parent.child');
return _this5.visit('/sister');
}).then(function () {
assert.equal(_this5.routerService.get('currentRouteName'), 'parent.sister');
return _this5.visit('/brother');
}).then(function () {
assert.equal(_this5.routerService.get('currentRouteName'), 'parent.brother');
});
};
_class.prototype['@test RouterService#rootURL is correctly set to the default value'] = function testRouterServiceRootURLIsCorrectlySetToTheDefaultValue(assert) {
var _this6 = this;
assert.expect(1);
return this.visit('/').then(function () {
assert.equal(_this6.routerService.get('rootURL'), '/');
});
};
_class.prototype['@test RouterService#rootURL is correctly set to a custom value'] = function testRouterServiceRootURLIsCorrectlySetToACustomValue(assert) {
var _this7 = this;
assert.expect(1);
this.add('route:parent.index', _emberRouting.Route.extend({
init: function () {
this._super();
(0, _emberMetal.set)(this.router, 'rootURL', '/homepage');
}
}));
return this.visit('/').then(function () {
assert.equal(_this7.routerService.get('rootURL'), '/homepage');
});
};
_class.prototype['@test RouterService#location is correctly delegated from router:main'] = function testRouterServiceLocationIsCorrectlyDelegatedFromRouterMain(assert) {
var _this8 = this;
assert.expect(2);
return this.visit('/').then(function () {
var location = _this8.routerService.get('location');
assert.ok(location);
assert.ok(location instanceof _emberRouting.NoneLocation);
});
};
return _class;
}(_internalTestHelpers.RouterTestCase));
}
});
QUnit.module('ESLint | ember/tests/routing/router_service_test/basic_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/router_service_test/basic_test.js should pass ESLint\n\n');
});
enifed('ember/tests/routing/router_service_test/currenturl_lifecycle_test', ['ember-babel', 'ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers', 'ember/features'], function (_emberBabel, _emberRuntime, _emberGlimmer, _emberRouting, _emberMetal, _internalTestHelpers, _features) {
'use strict';
if (_features.EMBER_ROUTING_ROUTER_SERVICE) {
var results = [];
var ROUTE_NAMES = ['index', 'child', 'sister', 'brother'];
var InstrumentedRoute = _emberRouting.Route.extend({
routerService: _emberRuntime.inject.service('router'),
beforeModel: function () {
var service = (0, _emberMetal.get)(this, 'routerService');
results.push([service.get('currentRouteName'), 'beforeModel', service.get('currentURL')]);
},
model: function () {
var service = (0, _emberMetal.get)(this, 'routerService');
results.push([service.get('currentRouteName'), 'model', service.get('currentURL')]);
},
afterModel: function () {
var service = (0, _emberMetal.get)(this, 'routerService');
results.push([service.get('currentRouteName'), 'afterModel', service.get('currentURL')]);
}
});
(0, _internalTestHelpers.moduleFor)('Router Service - currentURL', function (_RouterTestCase) {
(0, _emberBabel.inherits)(_class, _RouterTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RouterTestCase.call(this));
results = [];
ROUTE_NAMES.forEach(function (name) {
var routeName = 'parent.' + name;
_this.add('route:' + routeName, InstrumentedRoute.extend());
_this.addTemplate(routeName, '{{current-url}}');
});
_this.addComponent('current-url', {
ComponentClass: _emberGlimmer.Component.extend({
routerService: _emberRuntime.inject.service('router'),
currentURL: (0, _emberRuntime.readOnly)('routerService.currentURL')
}),
template: '{{currentURL}}'
});
return _this;
}
_class.prototype['@test RouterService#currentURL is correctly set for top level route'] = function testRouterServiceCurrentURLIsCorrectlySetForTopLevelRoute(assert) {
var _this2 = this;
assert.expect(1);
return this.visit('/').then(function () {
assert.equal(_this2.routerService.get('currentURL'), '/');
});
};
_class.prototype['@test RouterService#currentURL is correctly set for child route'] = function testRouterServiceCurrentURLIsCorrectlySetForChildRoute(assert) {
var _this3 = this;
assert.expect(1);
return this.visit('/child').then(function () {
assert.equal(_this3.routerService.get('currentURL'), '/child');
});
};
_class.prototype['@test RouterService#currentURL is correctly set after transition'] = function testRouterServiceCurrentURLIsCorrectlySetAfterTransition(assert) {
var _this4 = this;
assert.expect(1);
return this.visit('/child').then(function () {
return _this4.routerService.transitionTo('parent.sister');
}).then(function () {
assert.equal(_this4.routerService.get('currentURL'), '/sister');
});
};
_class.prototype['@test RouterService#currentURL is correctly set on each transition'] = function testRouterServiceCurrentURLIsCorrectlySetOnEachTransition(assert) {
var _this5 = this;
assert.expect(3);
return this.visit('/child').then(function () {
assert.equal(_this5.routerService.get('currentURL'), '/child');
return _this5.visit('/sister');
}).then(function () {
assert.equal(_this5.routerService.get('currentURL'), '/sister');
return _this5.visit('/brother');
}).then(function () {
assert.equal(_this5.routerService.get('currentURL'), '/brother');
});
};
_class.prototype['@test RouterService#currentURL is not set during lifecycle hooks'] = function testRouterServiceCurrentURLIsNotSetDuringLifecycleHooks(assert) {
var _this6 = this;
assert.expect(2);
return this.visit('/').then(function () {
assert.deepEqual(results, [[null, 'beforeModel', null], [null, 'model', null], [null, 'afterModel', null]]);
results = [];
return _this6.visit('/child');
}).then(function () {
assert.deepEqual(results, [['parent.index', 'beforeModel', '/'], ['parent.index', 'model', '/'], ['parent.index', 'afterModel', '/']]);
});
};
_class.prototype['@test RouterService#currentURL is correctly set with component after consecutive visits'] = function testRouterServiceCurrentURLIsCorrectlySetWithComponentAfterConsecutiveVisits(assert) {
var _this7 = this;
assert.expect(3);
return this.visit('/').then(function () {
_this7.assertText('/');
return _this7.visit('/child');
}).then(function () {
_this7.assertText('/child');
return _this7.visit('/');
}).then(function () {
_this7.assertText('/');
});
};
return _class;
}(_internalTestHelpers.RouterTestCase));
}
});
QUnit.module('ESLint | ember/tests/routing/router_service_test/currenturl_lifecycle_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/router_service_test/currenturl_lifecycle_test.js should pass ESLint\n\n');
});
enifed('ember/tests/routing/router_service_test/isActive_test', ['ember-babel', 'ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers', 'ember/features'], function (_emberBabel, _emberRuntime, _emberGlimmer, _emberRouting, _emberMetal, _internalTestHelpers, _features) {
'use strict';
if (_features.EMBER_ROUTING_ROUTER_SERVICE) {
(0, _internalTestHelpers.moduleFor)('Router Service - isActive', function (_RouterTestCase) {
(0, _emberBabel.inherits)(_class, _RouterTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RouterTestCase.apply(this, arguments));
}
_class.prototype['@test RouterService#isActive returns true for simple route'] = function testRouterServiceIsActiveReturnsTrueForSimpleRoute(assert) {
var _this2 = this;
assert.expect(1);
return this.visit('/').then(function () {
return _this2.routerService.transitionTo('parent.child');
}).then(function () {
return _this2.routerService.transitionTo('parent.sister');
}).then(function () {
assert.ok(_this2.routerService.isActive('parent.sister'));
});
};
_class.prototype['@test RouterService#isActive returns true for simple route with dynamic segments'] = function testRouterServiceIsActiveReturnsTrueForSimpleRouteWithDynamicSegments(assert) {
var _this3 = this;
assert.expect(1);
var dynamicModel = { id: 1 };
return this.visit('/').then(function () {
return _this3.routerService.transitionTo('dynamic', dynamicModel);
}).then(function () {
assert.ok(_this3.routerService.isActive('dynamic', dynamicModel));
});
};
_class.prototype['@test RouterService#isActive does not eagerly instantiate controller for query params'] = function testRouterServiceIsActiveDoesNotEagerlyInstantiateControllerForQueryParams(assert) {
var _this4 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ sort: 'ASC' });
this.add('controller:parent.sister', _emberRuntime.Controller.extend({
queryParams: ['sort'],
sort: 'ASC',
init: function () {
assert.ok(false, 'should never create');
this._super.apply(this, arguments);
}
}));
return this.visit('/').then(function () {
return _this4.routerService.transitionTo('parent.brother');
}).then(function () {
assert.notOk(_this4.routerService.isActive('parent.sister', queryParams));
});
};
_class.prototype['@test RouterService#isActive is correct for simple route with basic query params'] = function testRouterServiceIsActiveIsCorrectForSimpleRouteWithBasicQueryParams(assert) {
var _this5 = this;
assert.expect(2);
var queryParams = this.buildQueryParams({ sort: 'ASC' });
this.add('controller:parent.child', _emberRuntime.Controller.extend({
queryParams: ['sort'],
sort: 'ASC'
}));
return this.visit('/').then(function () {
return _this5.routerService.transitionTo('parent.child', queryParams);
}).then(function () {
assert.ok(_this5.routerService.isActive('parent.child', queryParams));
assert.notOk(_this5.routerService.isActive('parent.child', _this5.buildQueryParams({ sort: 'DESC' })));
});
};
_class.prototype['@test RouterService#isActive for simple route with array as query params'] = function testRouterServiceIsActiveForSimpleRouteWithArrayAsQueryParams(assert) {
var _this6 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ sort: ['ascending'] });
return this.visit('/').then(function () {
return _this6.routerService.transitionTo('parent.child', queryParams);
}).then(function () {
assert.notOk(_this6.routerService.isActive('parent.child', _this6.buildQueryParams({ sort: 'descending' })));
});
};
return _class;
}(_internalTestHelpers.RouterTestCase));
}
});
QUnit.module('ESLint | ember/tests/routing/router_service_test/isActive_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/router_service_test/isActive_test.js should pass ESLint\n\n');
});
enifed('ember/tests/routing/router_service_test/replaceWith_test', ['ember-babel', 'ember-routing', 'internal-test-helpers', 'router', 'ember-runtime', 'ember/features'], function (_emberBabel, _emberRouting, _internalTestHelpers, _router, _emberRuntime, _features) {
'use strict';
if (_features.EMBER_ROUTING_ROUTER_SERVICE) {
(0, _internalTestHelpers.moduleFor)('Router Service - replaceWith', function (_RouterTestCase) {
(0, _emberBabel.inherits)(_class, _RouterTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RouterTestCase.call(this));
var testCase = _this;
testCase.state = [];
_this.add('location:test', _emberRouting.NoneLocation.extend({
setURL: function (path) {
testCase.state.push(path);
this.set('path', path);
},
replaceURL: function (path) {
testCase.state.splice(testCase.state.length - 1, 1, path);
this.set('path', path);
}
}));
return _this;
}
_class.prototype['@test RouterService#replaceWith returns a Transition'] = function testRouterServiceReplaceWithReturnsATransition(assert) {
var _this2 = this;
assert.expect(1);
var transition = void 0;
return this.visit('/').then(function () {
transition = _this2.routerService.replaceWith('parent.child');
assert.ok(transition instanceof _router.Transition);
return transition;
});
};
_class.prototype['@test RouterService#replaceWith with basic route replaces location'] = function testRouterServiceReplaceWithWithBasicRouteReplacesLocation(assert) {
var _this3 = this;
assert.expect(1);
return this.visit('/').then(function () {
return _this3.routerService.transitionTo('parent.child');
}).then(function () {
return _this3.routerService.transitionTo('parent.sister');
}).then(function () {
return _this3.routerService.replaceWith('parent.brother');
}).then(function () {
assert.deepEqual(_this3.state, ['/', '/child', '/brother']);
});
};
_class.prototype['@test RouterService#replaceWith with basic route using URLs replaces location'] = function testRouterServiceReplaceWithWithBasicRouteUsingURLsReplacesLocation(assert) {
var _this4 = this;
assert.expect(1);
return this.visit('/').then(function () {
return _this4.routerService.transitionTo('/child');
}).then(function () {
return _this4.routerService.transitionTo('/sister');
}).then(function () {
return _this4.routerService.replaceWith('/brother');
}).then(function () {
assert.deepEqual(_this4.state, ['/', '/child', '/brother']);
});
};
_class.prototype['@test RouterService#replaceWith transitioning back to previously visited route replaces location'] = function testRouterServiceReplaceWithTransitioningBackToPreviouslyVisitedRouteReplacesLocation(assert) {
var _this5 = this;
assert.expect(1);
return this.visit('/').then(function () {
return _this5.routerService.transitionTo('parent.child');
}).then(function () {
return _this5.routerService.transitionTo('parent.sister');
}).then(function () {
return _this5.routerService.transitionTo('parent.brother');
}).then(function () {
return _this5.routerService.replaceWith('parent.sister');
}).then(function () {
assert.deepEqual(_this5.state, ['/', '/child', '/sister', '/sister']);
});
};
_class.prototype['@test RouterService#replaceWith with basic query params does not remove query param defaults'] = function testRouterServiceReplaceWithWithBasicQueryParamsDoesNotRemoveQueryParamDefaults(assert) {
var _this6 = this;
assert.expect(1);
this.add('controller:parent.child', _emberRuntime.Controller.extend({
queryParams: ['sort'],
sort: 'ASC'
}));
var queryParams = this.buildQueryParams({ sort: 'ASC' });
return this.visit('/').then(function () {
return _this6.routerService.transitionTo('parent.brother');
}).then(function () {
return _this6.routerService.replaceWith('parent.sister');
}).then(function () {
return _this6.routerService.replaceWith('parent.child', queryParams);
}).then(function () {
assert.deepEqual(_this6.state, ['/', '/child?sort=ASC']);
});
};
(0, _emberBabel.createClass)(_class, [{
key: 'routerOptions',
get: function () {
return {
location: 'test'
};
}
}]);
return _class;
}(_internalTestHelpers.RouterTestCase));
}
});
QUnit.module('ESLint | ember/tests/routing/router_service_test/replaceWith_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/router_service_test/replaceWith_test.js should pass ESLint\n\n');
});
enifed('ember/tests/routing/router_service_test/transitionTo_test', ['ember-babel', 'ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers', 'router', 'ember/features'], function (_emberBabel, _emberRuntime, _emberGlimmer, _emberRouting, _emberMetal, _internalTestHelpers, _router, _features) {
'use strict';
if (_features.EMBER_ROUTING_ROUTER_SERVICE) {
(0, _internalTestHelpers.moduleFor)('Router Service - transitionTo', function (_RouterTestCase) {
(0, _emberBabel.inherits)(_class, _RouterTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RouterTestCase.call(this));
var testCase = _this;
testCase.state = [];
_this.add('location:test', _emberRouting.NoneLocation.extend({
setURL: function (path) {
testCase.state.push(path);
this.set('path', path);
},
replaceURL: function (path) {
testCase.state.splice(testCase.state.length - 1, 1, path);
this.set('path', path);
}
}));
return _this;
}
_class.prototype['@test RouterService#transitionTo returns a Transition'] = function testRouterServiceTransitionToReturnsATransition(assert) {
var _this2 = this;
assert.expect(1);
var transition = void 0;
return this.visit('/').then(function () {
transition = _this2.routerService.transitionTo('parent.child');
assert.ok(transition instanceof _router.Transition);
return transition;
});
};
_class.prototype['@test RouterService#transitionTo with basic route updates location'] = function testRouterServiceTransitionToWithBasicRouteUpdatesLocation(assert) {
var _this3 = this;
assert.expect(1);
return this.visit('/').then(function () {
return _this3.routerService.transitionTo('parent.child');
}).then(function () {
return _this3.routerService.transitionTo('parent.sister');
}).then(function () {
return _this3.routerService.transitionTo('parent.brother');
}).then(function () {
assert.deepEqual(_this3.state, ['/', '/child', '/sister', '/brother']);
});
};
_class.prototype['@test RouterService#transitionTo transitioning back to previously visited route updates location'] = function testRouterServiceTransitionToTransitioningBackToPreviouslyVisitedRouteUpdatesLocation(assert) {
var _this4 = this;
assert.expect(1);
return this.visit('/').then(function () {
return _this4.routerService.transitionTo('parent.child');
}).then(function () {
return _this4.routerService.transitionTo('parent.sister');
}).then(function () {
return _this4.routerService.transitionTo('parent.brother');
}).then(function () {
return _this4.routerService.transitionTo('parent.sister');
}).then(function () {
assert.deepEqual(_this4.state, ['/', '/child', '/sister', '/brother', '/sister']);
});
};
_class.prototype['@test RouterService#transitionTo with basic route'] = function testRouterServiceTransitionToWithBasicRoute(assert) {
var _this5 = this;
assert.expect(1);
var componentInstance = void 0;
this.addTemplate('parent.index', '{{foo-bar}}');
this.addComponent('foo-bar', {
ComponentClass: _emberGlimmer.Component.extend({
routerService: _emberRuntime.inject.service('router'),
init: function () {
this._super();
componentInstance = this;
},
actions: {
transitionToSister: function () {
(0, _emberMetal.get)(this, 'routerService').transitionTo('parent.sister');
}
}
}),
template: 'foo-bar'
});
return this.visit('/').then(function () {
(0, _emberMetal.run)(function () {
componentInstance.send('transitionToSister');
});
assert.equal(_this5.routerService.get('currentRouteName'), 'parent.sister');
});
};
_class.prototype['@test RouterService#transitionTo with basic route using URL'] = function testRouterServiceTransitionToWithBasicRouteUsingURL(assert) {
var _this6 = this;
assert.expect(1);
var componentInstance = void 0;
this.addTemplate('parent.index', '{{foo-bar}}');
this.addComponent('foo-bar', {
ComponentClass: _emberGlimmer.Component.extend({
routerService: _emberRuntime.inject.service('router'),
init: function () {
this._super();
componentInstance = this;
},
actions: {
transitionToSister: function () {
(0, _emberMetal.get)(this, 'routerService').transitionTo('/sister');
}
}
}),
template: 'foo-bar'
});
return this.visit('/').then(function () {
(0, _emberMetal.run)(function () {
componentInstance.send('transitionToSister');
});
assert.equal(_this6.routerService.get('currentRouteName'), 'parent.sister');
});
};
_class.prototype['@test RouterService#transitionTo with dynamic segment'] = function testRouterServiceTransitionToWithDynamicSegment(assert) {
var _this7 = this;
assert.expect(3);
var componentInstance = void 0;
var dynamicModel = { id: 1, contents: 'much dynamicism' };
this.addTemplate('parent.index', '{{foo-bar}}');
this.addTemplate('dynamic', '{{model.contents}}');
this.addComponent('foo-bar', {
ComponentClass: _emberGlimmer.Component.extend({
routerService: _emberRuntime.inject.service('router'),
init: function () {
this._super();
componentInstance = this;
},
actions: {
transitionToDynamic: function () {
(0, _emberMetal.get)(this, 'routerService').transitionTo('dynamic', dynamicModel);
}
}
}),
template: 'foo-bar'
});
return this.visit('/').then(function () {
(0, _emberMetal.run)(function () {
componentInstance.send('transitionToDynamic');
});
assert.equal(_this7.routerService.get('currentRouteName'), 'dynamic');
assert.equal(_this7.routerService.get('currentURL'), '/dynamic/1');
_this7.assertText('much dynamicism');
});
};
_class.prototype['@test RouterService#transitionTo with dynamic segment and model hook'] = function testRouterServiceTransitionToWithDynamicSegmentAndModelHook(assert) {
var _this8 = this;
assert.expect(3);
var componentInstance = void 0;
var dynamicModel = { id: 1, contents: 'much dynamicism' };
this.add('route:dynamic', _emberRouting.Route.extend({
model: function () {
return dynamicModel;
}
}));
this.addTemplate('parent.index', '{{foo-bar}}');
this.addTemplate('dynamic', '{{model.contents}}');
this.addComponent('foo-bar', {
ComponentClass: _emberGlimmer.Component.extend({
routerService: _emberRuntime.inject.service('router'),
init: function () {
this._super();
componentInstance = this;
},
actions: {
transitionToDynamic: function () {
(0, _emberMetal.get)(this, 'routerService').transitionTo('dynamic', 1);
}
}
}),
template: 'foo-bar'
});
return this.visit('/').then(function () {
(0, _emberMetal.run)(function () {
componentInstance.send('transitionToDynamic');
});
assert.equal(_this8.routerService.get('currentRouteName'), 'dynamic');
assert.equal(_this8.routerService.get('currentURL'), '/dynamic/1');
_this8.assertText('much dynamicism');
});
};
_class.prototype['@test RouterService#transitionTo with basic query params does not remove query param defaults'] = function testRouterServiceTransitionToWithBasicQueryParamsDoesNotRemoveQueryParamDefaults(assert) {
var _this9 = this;
assert.expect(1);
this.add('controller:parent.child', _emberRuntime.Controller.extend({
queryParams: ['sort'],
sort: 'ASC'
}));
var queryParams = this.buildQueryParams({ sort: 'ASC' });
return this.visit('/').then(function () {
return _this9.routerService.transitionTo('parent.child', queryParams);
}).then(function () {
assert.equal(_this9.routerService.get('currentURL'), '/child?sort=ASC');
});
};
_class.prototype['@test RouterService#transitionTo with aliased query params uses the original provided key'] = function testRouterServiceTransitionToWithAliasedQueryParamsUsesTheOriginalProvidedKey(assert) {
var _this10 = this;
assert.expect(1);
this.add('controller:parent.child', _emberRuntime.Controller.extend({
queryParams: {
'cont_sort': 'url_sort'
},
cont_sort: 'ASC'
}));
var queryParams = this.buildQueryParams({ url_sort: 'ASC' });
return this.visit('/').then(function () {
return _this10.routerService.transitionTo('parent.child', queryParams);
}).then(function () {
assert.equal(_this10.routerService.get('currentURL'), '/child?url_sort=ASC');
});
};
_class.prototype['@test RouterService#transitionTo with aliased query params uses the original provided key when controller property name'] = function testRouterServiceTransitionToWithAliasedQueryParamsUsesTheOriginalProvidedKeyWhenControllerPropertyName(assert) {
var _this11 = this;
assert.expect(1);
this.add('controller:parent.child', _emberRuntime.Controller.extend({
queryParams: {
'cont_sort': 'url_sort'
},
cont_sort: 'ASC'
}));
var queryParams = this.buildQueryParams({ cont_sort: 'ASC' });
return this.visit('/').then(function () {
expectAssertion(function () {
return _this11.routerService.transitionTo('parent.child', queryParams);
}, 'You passed the `cont_sort` query parameter during a transition into parent.child, please update to url_sort');
});
};
(0, _emberBabel.createClass)(_class, [{
key: 'routerOptions',
get: function () {
return {
location: 'test'
};
}
}]);
return _class;
}(_internalTestHelpers.RouterTestCase));
}
});
QUnit.module('ESLint | ember/tests/routing/router_service_test/transitionTo_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/router_service_test/transitionTo_test.js should pass ESLint\n\n');
});
enifed('ember/tests/routing/router_service_test/urlFor_test', ['ember-babel', 'ember-runtime', 'ember-routing', 'ember-metal', 'internal-test-helpers', 'ember/features'], function (_emberBabel, _emberRuntime, _emberRouting, _emberMetal, _internalTestHelpers, _features) {
'use strict';
function setupController(app, name) {
var controllerName = _emberRuntime.String.capitalize(name) + 'Controller';
Object.defineProperty(app, controllerName, {
get: function () {
throw new Error('Generating a URL should not require instantiation of a ' + controllerName + '.');
}
});
}
if (_features.EMBER_ROUTING_ROUTER_SERVICE) {
(0, _internalTestHelpers.moduleFor)('Router Service - urlFor', function (_RouterTestCase) {
(0, _emberBabel.inherits)(_class, _RouterTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _RouterTestCase.apply(this, arguments));
}
_class.prototype['@test RouterService#urlFor returns URL for simple route'] = function testRouterServiceUrlForReturnsURLForSimpleRoute(assert) {
var _this2 = this;
assert.expect(1);
return this.visit('/').then(function () {
var expectedURL = _this2.routerService.urlFor('parent.child');
assert.equal('/child', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with dynamic segments'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithDynamicSegments(assert) {
var _this3 = this;
assert.expect(1);
setupController(this.application, 'dynamic');
var dynamicModel = { id: 1, contents: 'much dynamicism' };
return this.visit('/').then(function () {
var expectedURL = _this3.routerService.urlFor('dynamic', dynamicModel);
assert.equal('/dynamic/1', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with basic query params'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithBasicQueryParams(assert) {
var _this4 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ foo: 'bar' });
return this.visit('/').then(function () {
var expectedURL = _this4.routerService.urlFor('parent.child', queryParams);
assert.equal('/child?foo=bar', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with basic query params and default value'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithBasicQueryParamsAndDefaultValue(assert) {
var _this5 = this;
assert.expect(1);
this.add('controller:parent.child', _emberRuntime.Controller.extend({
queryParams: ['sort'],
sort: 'ASC'
}));
var queryParams = this.buildQueryParams({ sort: 'ASC' });
return this.visit('/').then(function () {
var expectedURL = _this5.routerService.urlFor('parent.child', queryParams);
assert.equal('/child?sort=ASC', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with basic query params and default value with stickyness'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithBasicQueryParamsAndDefaultValueWithStickyness(assert) {
var _this6 = this;
assert.expect(2);
this.add('controller:parent.child', _emberRuntime.Controller.extend({
queryParams: ['sort', 'foo'],
sort: 'ASC'
}));
var queryParams = this.buildQueryParams({ sort: 'DESC' });
return this.visit('/child/?sort=DESC').then(function () {
var controller = _this6.applicationInstance.lookup('controller:parent.child');
assert.equal((0, _emberMetal.get)(controller, 'sort'), 'DESC', 'sticky is set');
var queryParams = _this6.buildQueryParams({ foo: 'derp' });
var actual = _this6.routerService.urlFor('parent.child', queryParams);
assert.equal(actual, '/child?foo=derp', 'does not use "stickiness"');
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with array as query params'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithArrayAsQueryParams(assert) {
var _this7 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ selectedItems: ['a', 'b', 'c'] });
return this.visit('/').then(function () {
var expectedURL = _this7.routerService.urlFor('parent.child', queryParams);
assert.equal('/child?selectedItems[]=a&selectedItems[]=b&selectedItems[]=c', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with null query params'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithNullQueryParams(assert) {
var _this8 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ foo: null });
return this.visit('/').then(function () {
var expectedURL = _this8.routerService.urlFor('parent.child', queryParams);
assert.equal('/child', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with undefined query params'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithUndefinedQueryParams(assert) {
var _this9 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ foo: undefined });
return this.visit('/').then(function () {
var expectedURL = _this9.routerService.urlFor('parent.child', queryParams);
assert.equal('/child', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with dynamic segments and basic query params'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithDynamicSegmentsAndBasicQueryParams(assert) {
var _this10 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ foo: 'bar' });
return this.visit('/').then(function () {
var expectedURL = _this10.routerService.urlFor('dynamic', { id: 1 }, queryParams);
assert.equal('/dynamic/1?foo=bar', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with dynamic segments and array as query params'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithDynamicSegmentsAndArrayAsQueryParams(assert) {
var _this11 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ selectedItems: ['a', 'b', 'c'] });
return this.visit('/').then(function () {
var expectedURL = _this11.routerService.urlFor('dynamic', { id: 1 }, queryParams);
assert.equal('/dynamic/1?selectedItems[]=a&selectedItems[]=b&selectedItems[]=c', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with dynamic segments and null query params'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithDynamicSegmentsAndNullQueryParams(assert) {
var _this12 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ foo: null });
return this.visit('/').then(function () {
var expectedURL = _this12.routerService.urlFor('dynamic', { id: 1 }, queryParams);
assert.equal('/dynamic/1', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor returns URL for simple route with dynamic segments and undefined query params'] = function testRouterServiceUrlForReturnsURLForSimpleRouteWithDynamicSegmentsAndUndefinedQueryParams(assert) {
var _this13 = this;
assert.expect(1);
var queryParams = this.buildQueryParams({ foo: undefined });
return this.visit('/').then(function () {
var expectedURL = _this13.routerService.urlFor('dynamic', { id: 1 }, queryParams);
assert.equal('/dynamic/1', expectedURL);
});
};
_class.prototype['@test RouterService#urlFor correctly transitions to route via generated path'] = function testRouterServiceUrlForCorrectlyTransitionsToRouteViaGeneratedPath(assert) {
var _this14 = this;
assert.expect(1);
var expectedURL = void 0;
return this.visit('/').then(function () {
expectedURL = _this14.routerService.urlFor('parent.child');
return _this14.routerService.transitionTo(expectedURL);
}).then(function () {
assert.equal(expectedURL, _this14.routerService.get('currentURL'));
});
};
_class.prototype['@test RouterService#urlFor correctly transitions to route via generated path with dynamic segments'] = function testRouterServiceUrlForCorrectlyTransitionsToRouteViaGeneratedPathWithDynamicSegments(assert) {
var _this15 = this;
assert.expect(1);
var expectedURL = void 0;
var dynamicModel = { id: 1 };
this.add('route:dynamic', _emberRouting.Route.extend({
model: function () {
return dynamicModel;
}
}));
return this.visit('/').then(function () {
expectedURL = _this15.routerService.urlFor('dynamic', dynamicModel);
return _this15.routerService.transitionTo(expectedURL);
}).then(function () {
assert.equal(expectedURL, _this15.routerService.get('currentURL'));
});
};
_class.prototype['@test RouterService#urlFor correctly transitions to route via generated path with query params'] = function testRouterServiceUrlForCorrectlyTransitionsToRouteViaGeneratedPathWithQueryParams(assert) {
var _this16 = this;
assert.expect(1);
var expectedURL = void 0;
var actualURL = void 0;
var queryParams = this.buildQueryParams({ foo: 'bar' });
return this.visit('/').then(function () {
expectedURL = _this16.routerService.urlFor('parent.child', queryParams);
return _this16.routerService.transitionTo(expectedURL);
}).then(function () {
actualURL = _this16.routerService.get('currentURL') + '?foo=bar';
assert.equal(expectedURL, actualURL);
});
};
_class.prototype['@test RouterService#urlFor correctly transitions to route via generated path with dynamic segments and query params'] = function testRouterServiceUrlForCorrectlyTransitionsToRouteViaGeneratedPathWithDynamicSegmentsAndQueryParams(assert) {
var _this17 = this;
assert.expect(1);
var expectedURL = void 0;
var actualURL = void 0;
var queryParams = this.buildQueryParams({ foo: 'bar' });
var dynamicModel = { id: 1 };
this.add('route:dynamic', _emberRouting.Route.extend({
model: function () {
return dynamicModel;
}
}));
return this.visit('/').then(function () {
expectedURL = _this17.routerService.urlFor('dynamic', dynamicModel, queryParams);
return _this17.routerService.transitionTo(expectedURL);
}).then(function () {
actualURL = _this17.routerService.get('currentURL') + '?foo=bar';
assert.equal(expectedURL, actualURL);
});
};
return _class;
}(_internalTestHelpers.RouterTestCase));
}
});
QUnit.module('ESLint | ember/tests/routing/router_service_test/urlFor_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/router_service_test/urlFor_test.js should pass ESLint\n\n');
});
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 broModel = {};
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', broModel);
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 (transition, route) {
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(5);
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;
}
}
});
bootApplication('/grandma/mom/sally');
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 (err) {
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(5);
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;
}
}
});
bootApplication('/grandma/mom/sally');
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(1);
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?'
});
}
});
bootApplication('/foo/bar');
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(1);
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;
}
});
bootApplication('/foo');
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(2);
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 {};
}
}
});
bootApplication();
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');
});
});
QUnit.module('ESLint | ember/tests/routing/substates_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/substates_test.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, _class);
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Topmost template always get an element'] = function testTopmostTemplateAlwaysGetAnElement(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));
});
QUnit.module('ESLint | ember/tests/routing/toplevel_dom_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/routing/toplevel_dom_test.js should pass ESLint\n\n');
});
enifed('ember/tests/view_instrumentation_test', ['ember-babel', 'ember-metal', 'internal-test-helpers'], function (_emberBabel, _emberMetal, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('View Instrumentation', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
(0, _emberBabel.classCallCheck)(this, _class);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this));
_this.addTemplate('application', '{{outlet}}');
_this.addTemplate('index', 'Index ');
_this.addTemplate('posts', 'Posts ');
_this.router.map(function () {
this.route('posts');
});
return _this;
}
_class.prototype.teardown = function teardown() {
(0, _emberMetal.instrumentationReset)();
_ApplicationTestCase.prototype.teardown.call(this);
};
_class.prototype['@test Nodes without view instances are instrumented'] = function testNodesWithoutViewInstancesAreInstrumented(assert) {
var _this2 = this;
var called = false;
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function () {
called = true;
},
after: function () {}
});
return this.visit('/').then(function () {
assert.equal(_this2.textValue(), 'Index', 'It rendered the correct template');
assert.ok(called, 'Instrumentation called on first render');
called = false;
return _this2.visit('/posts');
}).then(function () {
assert.equal(_this2.textValue(), 'Posts', 'It rendered the correct template');
assert.ok(called, 'Instrumentation called on transition to non-view backed route');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
QUnit.module('ESLint | ember/tests/view_instrumentation_test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'ember/tests/view_instrumentation_test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | error_handler.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'error_handler.js should pass ESLint\n\n');
});
QUnit.module('ESLint | events.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'events.js should pass ESLint\n\n');
});
QUnit.module('ESLint | expand_properties.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'expand_properties.js should pass ESLint\n\n');
});
QUnit.module('ESLint | get_properties.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'get_properties.js should pass ESLint\n\n');
});
QUnit.module('ESLint | index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'index.js should pass ESLint\n\n');
});
QUnit.module('ESLint | injected_property.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'injected_property.js should pass ESLint\n\n');
});
QUnit.module('ESLint | instrumentation.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'instrumentation.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/apply-mixins', ['exports', 'ember-utils'], function (exports, _emberUtils) {
'use strict';
exports.default = applyMixins;
function isGenerator(mixin) {
return Array.isArray(mixin.cases) && typeof mixin.generate === 'function';
}
function applyMixins(TestClass) {
for (var _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;
if (isGenerator(mixinOrGenerator)) {
var 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;
}
});
QUnit.module('ESLint | internal-test-helpers/apply-mixins.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/apply-mixins.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/build-owner', ['exports', 'container', 'ember-routing', 'ember-application', 'ember-runtime'], function (exports, _container, _emberRouting, _emberApplication, _emberRuntime) {
'use strict';
exports.default = buildOwner;
function buildOwner() {
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;
}
});
QUnit.module('ESLint | internal-test-helpers/build-owner.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/build-owner.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/confirm-export', ['exports', 'require'], function (exports, _require2) {
'use strict';
exports.default = confirmExport;
function getDescriptor(obj, path) {
var parts = path.split('.');
var value = obj;
for (var i = 0; i < parts.length - 1; i++) {
var part = parts[i];
value = value[part];
if (!value) {
return undefined;
}
}
var last = parts[parts.length - 1];
return Object.getOwnPropertyDescriptor(value, last);
}
function confirmExport(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');
}
}
}
});
QUnit.module('ESLint | internal-test-helpers/confirm-export.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/confirm-export.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/equal-inner-html', ['exports'], function (exports) {
'use strict';
exports.default = equalInnerHTML;
// 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;
}
function equalInnerHTML(fragment, html) {
var actualHTML = normalizeInnerHTML(fragment.innerHTML);
QUnit.push(actualHTML === html, actualHTML, html);
}
});
QUnit.module('ESLint | internal-test-helpers/equal-inner-html.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/equal-inner-html.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/equal-tokens', ['exports', 'simple-html-tokenizer'], function (exports, _simpleHtmlTokenizer) {
'use strict';
exports.default = equalTokens;
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;
});
}
});
}
function equalTokens(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);
}
}
});
QUnit.module('ESLint | internal-test-helpers/equal-tokens.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/equal-tokens.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/factory', ['exports'], function (exports) {
'use strict';
exports.default = factory;
function setProperties(object, properties) {
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
object[key] = properties[key];
}
}
}
var guids = 0;
function factory() {
/*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;
}
}
});
QUnit.module('ESLint | internal-test-helpers/factory.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/factory.js should pass ESLint\n\n');
});
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-cases/default-resolver-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, _defaultResolverApplication, _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, 'DefaultResolverApplicationTestCase', {
enumerable: true,
get: function () {
return _defaultResolverApplication.default;
}
});
Object.defineProperty(exports, 'TestResolver', {
enumerable: true,
get: function () {
return _testResolver.default;
}
});
Object.defineProperty(exports, 'ModuleBasedTestResolver', {
enumerable: true,
get: function () {
return _testResolver.ModuleBasedResolver;
}
});
});
QUnit.module('ESLint | internal-test-helpers/index.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/index.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/matchers', ['exports'], function (exports) {
'use strict';
exports.regex = regex;
exports.classes = classes;
exports.styles = styles;
exports.equalsElement = equalsElement;
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;
}
function regex(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;
}
function classes(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;
}
function styles(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;
}
function equalsElement(element, tagName, attributes, content) {
QUnit.push(element.tagName === tagName.toUpperCase(), element.tagName.toLowerCase(), tagName, 'expect tagName to be ' + tagName);
var expectedAttrs = {};
var expectedCount = 0;
for (var name in attributes) {
var expected = attributes[name];
if (expected !== null) {
expectedCount++;
}
var 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 (var 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');
}
}
}
});
QUnit.module('ESLint | internal-test-helpers/matchers.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/matchers.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/module-for', ['exports', 'ember-runtime', 'internal-test-helpers/apply-mixins'], function (exports, _emberRuntime, _applyMixins) {
'use strict';
exports.default = moduleFor;
function moduleFor(description, TestClass) {
var context = void 0;
QUnit.module(description, {
setup: function () {
context = new TestClass();
if (context.beforeEach) {
return context.beforeEach();
}
},
teardown: function () {
context.teardown();
}
});
for (var _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);
});
}
}
}
});
QUnit.module('ESLint | internal-test-helpers/module-for.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/module-for.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/run', ['exports', 'ember-metal'], function (exports, _emberMetal) {
'use strict';
exports.runAppend = runAppend;
exports.runDestroy = runDestroy;
function runAppend(view) {
(0, _emberMetal.run)(view, 'appendTo', '#qunit-fixture');
}
function runDestroy(toDestroy) {
if (toDestroy) {
(0, _emberMetal.run)(toDestroy, 'destroy');
}
}
});
QUnit.module('ESLint | internal-test-helpers/run.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/run.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/strip', ['exports'], function (exports) {
'use strict';
exports.default = strip;
function strip(_ref) {
for (var _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);
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('');
}
});
QUnit.module('ESLint | internal-test-helpers/strip.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/strip.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/test-cases/abstract-application', ['exports', 'ember-babel', 'ember-template-compiler', 'internal-test-helpers/test-cases/abstract', 'ember-views', 'internal-test-helpers/run'], function (exports, _emberBabel, _emberTemplateCompiler, _abstract, _emberViews, _run) {
'use strict';
var AbstractApplicationTestCase = function (_AbstractTestCase) {
(0, _emberBabel.inherits)(AbstractApplicationTestCase, _AbstractTestCase);
function AbstractApplicationTestCase() {
(0, _emberBabel.classCallCheck)(this, AbstractApplicationTestCase);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.call(this));
_this.element = (0, _emberViews.jQuery)('#qunit-fixture')[0];
return _this;
}
AbstractApplicationTestCase.prototype.teardown = function teardown() {
(0, _run.runDestroy)(this.application);
_AbstractTestCase.prototype.teardown.call(this);
};
AbstractApplicationTestCase.prototype.compile = function compile(string, options) {
return _emberTemplateCompiler.compile.apply(undefined, arguments);
};
(0, _emberBabel.createClass)(AbstractApplicationTestCase, [{
key: 'applicationOptions',
get: function () {
return {
rootElement: '#qunit-fixture'
};
}
}, {
key: 'routerOptions',
get: function () {
return {
location: 'none'
};
}
}, {
key: 'router',
get: function () {
return this.application.resolveRegistration('router:main');
}
}]);
return AbstractApplicationTestCase;
}(_abstract.default);
exports.default = AbstractApplicationTestCase;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/abstract-application.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/abstract-application.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, AbstractRenderingTestCase);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.call(this));
var bootOptions = _this.getBootOptions();
var owner = _this.owner = (0, _buildOwner.default)({
ownerOptions: _this.getOwnerOptions(),
resolver: _this.getResolver(),
bootOptions: bootOptions
});
_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');
if (!bootOptions || bootOptions.isInteractive !== false) {
owner.lookup('event_dispatcher:main').setup(_this.getCustomDispatcherEvents(), _this.element);
}
return _this;
}
AbstractRenderingTestCase.prototype.compile = function compile() {
return _emberTemplateCompiler.compile.apply(undefined, arguments);
};
AbstractRenderingTestCase.prototype.getCustomDispatcherEvents = function getCustomDispatcherEvents() {
return {};
};
AbstractRenderingTestCase.prototype.getOwnerOptions = function getOwnerOptions() {};
AbstractRenderingTestCase.prototype.getBootOptions = function getBootOptions() {};
AbstractRenderingTestCase.prototype.getResolver = function getResolver() {};
AbstractRenderingTestCase.prototype.teardown = function teardown() {
try {
if (this.component) {
(0, _run.runDestroy)(this.component);
}
if (this.owner) {
(0, _run.runDestroy)(this.owner);
}
} finally {
(0, _emberGlimmer._resetRenderers)();
}
};
AbstractRenderingTestCase.prototype.render = function render(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 rerender() {
this.component.rerender();
};
AbstractRenderingTestCase.prototype.registerHelper = function registerHelper(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 registerPartial(name, template) {
var owner = this.env.owner || this.owner;
if (typeof template === 'string') {
var moduleName = 'template:' + name;
owner.register(moduleName, this.compile(template, { moduleName: moduleName }));
}
};
AbstractRenderingTestCase.prototype.registerComponent = function registerComponent(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 registerTemplate(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 registerService(name, klass) {
this.owner.register('service:' + name, klass);
};
AbstractRenderingTestCase.prototype.assertTextNode = function assertTextNode(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;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/abstract-rendering.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/abstract-rendering.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, AbstractTestCase);
this.element = null;
this.snapshot = null;
this.assert = QUnit.config.current.assert;
}
AbstractTestCase.prototype.teardown = function teardown() {};
AbstractTestCase.prototype.runTask = function runTask(callback) {
return (0, _emberMetal.run)(callback);
};
AbstractTestCase.prototype.runTaskNext = function runTaskNext(callback) {
return _emberMetal.run.next(callback);
};
AbstractTestCase.prototype.nthChild = function nthChild(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.click = function click(selector) {
return this.$(selector).click();
};
AbstractTestCase.prototype.textValue = function textValue() {
return this.$().text();
};
AbstractTestCase.prototype.takeSnapshot = function takeSnapshot() {
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 assertText(text) {
this.assert.strictEqual(this.textValue(), text, '#qunit-fixture content should be: `' + text + '`');
};
AbstractTestCase.prototype.assertInnerHTML = function assertInnerHTML(html) {
(0, _equalInnerHtml.default)(this.element, html);
};
AbstractTestCase.prototype.assertHTML = function assertHTML(html) {
(0, _equalTokens.default)(this.element, html, '#qunit-fixture content should be: `' + html + '`');
};
AbstractTestCase.prototype.assertElement = function assertElement(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 assertComponentElement(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 assertSameNode(actual, expected) {
this.assert.strictEqual(actual, expected, 'DOM node stability');
};
AbstractTestCase.prototype.assertInvariants = function assertInvariants(oldSnapshot, newSnapshot) {
oldSnapshot = oldSnapshot || this.snapshot;
newSnapshot = newSnapshot || this.takeSnapshot();
this.assert.strictEqual(newSnapshot.length, oldSnapshot.length, 'Same number of nodes');
for (var i = 0; i < oldSnapshot.length; i++) {
this.assertSameNode(newSnapshot[i], oldSnapshot[i]);
}
};
AbstractTestCase.prototype.assertPartialInvariants = function assertPartialInvariants(start, end) {
this.assertInvariants(this.snapshot, this.takeSnapshot().slice(start, end));
};
AbstractTestCase.prototype.assertStableRerender = function assertStableRerender() {
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;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/abstract.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/abstract.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/test-cases/application', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/test-resolver-application', 'ember-application', 'ember-routing', 'ember-utils', 'internal-test-helpers/run'], function (exports, _emberBabel, _testResolverApplication, _emberApplication, _emberRouting, _emberUtils, _run) {
'use strict';
var ApplicationTestCase = function (_TestResolverApplicat) {
(0, _emberBabel.inherits)(ApplicationTestCase, _TestResolverApplicat);
function ApplicationTestCase() {
(0, _emberBabel.classCallCheck)(this, ApplicationTestCase);
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _TestResolverApplicat.call(this));
var applicationOptions = _this.applicationOptions;
_this.application = _this.runTask(function () {
return _this.createApplication(applicationOptions);
});
_this.resolver = applicationOptions.Resolver.lastInstance;
if (_this.resolver) {
_this.resolver.add('router:main', _emberRouting.Router.extend(_this.routerOptions));
}
return _this;
}
ApplicationTestCase.prototype.createApplication = function createApplication() {
var myOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var MyApplication = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _emberApplication.Application;
return MyApplication.create(myOptions);
};
ApplicationTestCase.prototype.teardown = function teardown() {
(0, _run.runDestroy)(this.applicationInstance);
_TestResolverApplicat.prototype.teardown.call(this);
};
ApplicationTestCase.prototype.visit = function visit(url, options) {
var _this2 = this;
var applicationInstance = this.applicationInstance;
if (applicationInstance) {
return this.runTask(function () {
return applicationInstance.visit(url, options);
});
} else {
return this.runTask(function () {
return _this2.application.visit(url, options).then(function (instance) {
_this2.applicationInstance = instance;
return instance;
});
});
}
};
ApplicationTestCase.prototype.transitionTo = function transitionTo() {
var _this3 = this,
_arguments = arguments;
return this.runTask(function () {
var _appRouter;
return (_appRouter = _this3.appRouter).transitionTo.apply(_appRouter, _arguments);
});
};
(0, _emberBabel.createClass)(ApplicationTestCase, [{
key: 'applicationOptions',
get: function () {
return (0, _emberUtils.assign)(_TestResolverApplicat.prototype.applicationOptions, {
autoboot: false
});
}
}, {
key: 'appRouter',
get: function () {
return this.applicationInstance.lookup('router:main');
}
}]);
return ApplicationTestCase;
}(_testResolverApplication.default);
exports.default = ApplicationTestCase;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/application.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/application.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/test-cases/autoboot-application', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/test-resolver-application', 'internal-test-helpers/test-resolver', 'ember-application', 'ember-utils', 'ember-routing'], function (exports, _emberBabel, _testResolverApplication, _testResolver, _emberApplication, _emberUtils, _emberRouting) {
'use strict';
var AutobootApplicationTestCase = function (_TestResolverApplicat) {
(0, _emberBabel.inherits)(AutobootApplicationTestCase, _TestResolverApplicat);
function AutobootApplicationTestCase() {
(0, _emberBabel.classCallCheck)(this, AutobootApplicationTestCase);
return (0, _emberBabel.possibleConstructorReturn)(this, _TestResolverApplicat.apply(this, arguments));
}
AutobootApplicationTestCase.prototype.createApplication = function createApplication(options) {
var MyApplication = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _emberApplication.Application;
var myOptions = (0, _emberUtils.assign)(this.applicationOptions, options);
var application = this.application = MyApplication.create(myOptions);
this.resolver = myOptions.Resolver.lastInstance;
if (this.resolver) {
this.resolver.add('router:main', _emberRouting.Router.extend(this.routerOptions));
}
return application;
};
AutobootApplicationTestCase.prototype.visit = function visit(url, options) {
var _this2 = this;
return this.runTask(function () {
return _this2.applicationInstance.visit(url, options);
});
};
(0, _emberBabel.createClass)(AutobootApplicationTestCase, [{
key: 'applicationInstance',
get: function () {
return this.application.__deprecatedInstance__;
}
}]);
return AutobootApplicationTestCase;
}(_testResolverApplication.default);
exports.default = AutobootApplicationTestCase;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/autoboot-application.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/autoboot-application.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/test-cases/default-resolver-application', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/abstract-application', 'ember-application', 'ember-glimmer', 'ember-utils', 'internal-test-helpers/run', 'ember-routing'], function (exports, _emberBabel, _abstractApplication, _emberApplication, _emberGlimmer, _emberUtils, _run, _emberRouting) {
'use strict';
var ApplicationTestCase = function (_AbstractApplicationT) {
(0, _emberBabel.inherits)(ApplicationTestCase, _AbstractApplicationT);
function ApplicationTestCase() {
(0, _emberBabel.classCallCheck)(this, ApplicationTestCase);
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractApplicationT.apply(this, arguments));
}
ApplicationTestCase.prototype.createApplication = function createApplication() {
var application = this.application = _emberApplication.Application.create(this.applicationOptions);
application.Router = _emberRouting.Router.extend(this.routerOptions);
return application;
};
ApplicationTestCase.prototype.teardown = function teardown() {
(0, _run.runDestroy)(this.applicationInstance);
_AbstractApplicationT.prototype.teardown.call(this);
(0, _emberGlimmer.setTemplates)({});
};
ApplicationTestCase.prototype.visit = function visit(url, options) {
var _this2 = this;
var applicationInstance = this.applicationInstance;
if (applicationInstance) {
return this.runTask(function () {
return applicationInstance.visit(url, options);
});
} else {
return this.runTask(function () {
return _this2.application.visit(url, options).then(function (instance) {
_this2.applicationInstance = instance;
});
});
}
};
ApplicationTestCase.prototype.transitionTo = function transitionTo() {
var _this3 = this,
_arguments = arguments;
return this.runTask(function () {
var _appRouter;
return (_appRouter = _this3.appRouter).transitionTo.apply(_appRouter, _arguments);
});
};
ApplicationTestCase.prototype.addTemplate = function addTemplate(name, templateString) {
var compiled = this.compile(templateString);
(0, _emberGlimmer.setTemplate)(name, compiled);
return compiled;
};
(0, _emberBabel.createClass)(ApplicationTestCase, [{
key: 'applicationOptions',
get: function () {
return (0, _emberUtils.assign)(_AbstractApplicationT.prototype.applicationOptions, {
autoboot: false,
Resolver: _emberApplication.Resolver
});
}
}, {
key: 'appRouter',
get: function () {
return this.applicationInstance.lookup('router:main');
}
}]);
return ApplicationTestCase;
}(_abstractApplication.default);
exports.default = ApplicationTestCase;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/default-resolver-application.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/default-resolver-application.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, 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 visitAndAssert(path) {
var _this2 = this;
return this.visit.apply(this, arguments).then(function () {
_this2.assertCurrentPath(path);
});
};
QueryParamTestCase.prototype.getController = function getController(name) {
return this.applicationInstance.lookup('controller:' + name);
};
QueryParamTestCase.prototype.getRoute = function getRoute(name) {
return this.applicationInstance.lookup('route:' + name);
};
QueryParamTestCase.prototype.setAndFlush = function setAndFlush(obj, prop, value) {
return (0, _emberMetal.run)(obj, 'set', prop, value);
};
QueryParamTestCase.prototype.assertCurrentPath = function assertCurrentPath(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 setSingleQPController(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 setMappedQPController(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;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/query-param.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/query-param.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, 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;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/rendering.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/rendering.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, 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;
}
RouterTestCase.prototype.buildQueryParams = function buildQueryParams(queryParams) {
return {
queryParams: queryParams
};
};
(0, _emberBabel.createClass)(RouterTestCase, [{
key: 'routerService',
get: function () {
return this.applicationInstance.lookup('service:router');
}
}]);
return RouterTestCase;
}(_application.default);
exports.default = RouterTestCase;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/router.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/router.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/test-cases/test-resolver-application', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/abstract-application', 'internal-test-helpers/test-resolver', 'ember-utils'], function (exports, _emberBabel, _abstractApplication, _testResolver, _emberUtils) {
'use strict';
var TestResolverApplicationTestCase = function (_AbstractApplicationT) {
(0, _emberBabel.inherits)(TestResolverApplicationTestCase, _AbstractApplicationT);
function TestResolverApplicationTestCase() {
(0, _emberBabel.classCallCheck)(this, TestResolverApplicationTestCase);
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractApplicationT.apply(this, arguments));
}
TestResolverApplicationTestCase.prototype.add = function add(specifier, factory) {
this.resolver.add(specifier, factory);
};
TestResolverApplicationTestCase.prototype.addTemplate = function addTemplate(templateName, templateString) {
this.resolver.add('template:' + templateName, this.compile(templateString, {
moduleName: templateName
}));
};
TestResolverApplicationTestCase.prototype.addComponent = function addComponent(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)(TestResolverApplicationTestCase, [{
key: 'applicationOptions',
get: function () {
return (0, _emberUtils.assign)(_AbstractApplicationT.prototype.applicationOptions, {
Resolver: _testResolver.ModuleBasedResolver
});
}
}]);
return TestResolverApplicationTestCase;
}(_abstractApplication.default);
exports.default = TestResolverApplicationTestCase;
});
QUnit.module('ESLint | internal-test-helpers/test-cases/test-resolver-application.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-cases/test-resolver-application.js should pass ESLint\n\n');
});
enifed('internal-test-helpers/test-groups', ['exports', 'ember-environment', 'ember-metal'], function (exports, _emberEnvironment, _emberMetal) {
'use strict';
exports.testBoth = testBoth;
exports.testWithDefault = testWithDefault;
// used by unit tests to test both accessor mode and non-accessor mode
function testBoth(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');
}
});
}
function testWithDefault(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');
}
});
}
});
QUnit.module('ESLint | internal-test-helpers/test-groups.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-groups.js should pass ESLint\n\n');
});
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() {
(0, _emberBabel.classCallCheck)(this, Resolver);
this._registered = {};
this.constructor.lastInstance = this;
}
Resolver.prototype.resolve = function resolve(specifier) {
return this._registered[specifier];
};
Resolver.prototype.add = function add(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 addTemplate(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 create() {
return new this();
};
return Resolver;
}();
exports.default = Resolver;
var ModuleBasedResolver = function (_Resolver) {
(0, _emberBabel.inherits)(ModuleBasedResolver, _Resolver);
function ModuleBasedResolver() {
(0, _emberBabel.classCallCheck)(this, 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;
});
QUnit.module('ESLint | internal-test-helpers/test-resolver.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/test-resolver.js should pass ESLint\n\n');
});
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`');
});
});
QUnit.module('ESLint | internal-test-helpers/tests/index-test.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'internal-test-helpers/tests/index-test.js should pass ESLint\n\n');
});
QUnit.module('ESLint | is_blank.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'is_blank.js should pass ESLint\n\n');
});
QUnit.module('ESLint | is_empty.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'is_empty.js should pass ESLint\n\n');
});
QUnit.module('ESLint | is_none.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'is_none.js should pass ESLint\n\n');
});
QUnit.module('ESLint | is_present.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'is_present.js should pass ESLint\n\n');
});
QUnit.module('ESLint | is_proxy.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'is_proxy.js should pass ESLint\n\n');
});
QUnit.module('ESLint | libraries.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'libraries.js should pass ESLint\n\n');
});
QUnit.module('ESLint | map.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'map.js should pass ESLint\n\n');
});
QUnit.module('ESLint | merge.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'merge.js should pass ESLint\n\n');
});
QUnit.module('ESLint | meta.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'meta.js should pass ESLint\n\n');
});
QUnit.module('ESLint | meta_listeners.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'meta_listeners.js should pass ESLint\n\n');
});
QUnit.module('ESLint | mixin.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'mixin.js should pass ESLint\n\n');
});
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
}
});
QUnit.module('ESLint | observer.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'observer.js should pass ESLint\n\n');
});
QUnit.module('ESLint | observer_set.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'observer_set.js should pass ESLint\n\n');
});
QUnit.module('ESLint | path_cache.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'path_cache.js should pass ESLint\n\n');
});
QUnit.module('ESLint | properties.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'properties.js should pass ESLint\n\n');
});
QUnit.module('ESLint | property_events.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'property_events.js should pass ESLint\n\n');
});
QUnit.module('ESLint | property_get.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'property_get.js should pass ESLint\n\n');
});
QUnit.module('ESLint | property_set.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'property_set.js should pass ESLint\n\n');
});
QUnit.module('ESLint | replace.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'replace.js should pass ESLint\n\n');
});
QUnit.module('ESLint | run_loop.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'run_loop.js should pass ESLint\n\n');
});
QUnit.module('ESLint | set_properties.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'set_properties.js should pass ESLint\n\n');
});
QUnit.module('ESLint | tags.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'tags.js should pass ESLint\n\n');
});
QUnit.module('ESLint | transaction.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'transaction.js should pass ESLint\n\n');
});
QUnit.module('ESLint | watch_key.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'watch_key.js should pass ESLint\n\n');
});
QUnit.module('ESLint | watch_path.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'watch_path.js should pass ESLint\n\n');
});
QUnit.module('ESLint | watching.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'watching.js should pass ESLint\n\n');
});
QUnit.module('ESLint | weak_map.js');
QUnit.test('should pass ESLint', function(assert) {
assert.expect(1);
assert.ok(true, 'weak_map.js should pass ESLint\n\n');
});
}());
//# sourceMappingURL=ember-tests.map