From 32d83e942d32e33d0121d3b6430486eb0366b707 Mon Sep 17 00:00:00 2001 From: Joel Kang Date: Mon, 28 Mar 2016 16:50:35 -0700 Subject: [PATCH] [Glimmer2][WIP] Migrate bindings integration test --- .../integration/binding_integration_test.js | 54 +++++++ .../tests/integration/content-test.js | 16 ++ .../integration/binding_integration_test.js | 147 +----------------- 3 files changed, 71 insertions(+), 146 deletions(-) create mode 100644 packages/ember-glimmer/tests/integration/binding_integration_test.js mode change 100644 => 120000 packages/ember-htmlbars/tests/integration/binding_integration_test.js diff --git a/packages/ember-glimmer/tests/integration/binding_integration_test.js b/packages/ember-glimmer/tests/integration/binding_integration_test.js new file mode 100644 index 00000000000..758c40f776a --- /dev/null +++ b/packages/ember-glimmer/tests/integration/binding_integration_test.js @@ -0,0 +1,54 @@ +import { RenderingTest, moduleFor } from '../utils/test-case'; +import { Component } from '../utils/helpers'; +import { set } from 'ember-metal/property_set'; +import { Binding } from 'ember-metal/binding'; + +moduleFor('Binding integration tests', class extends RenderingTest { + + ['@htmlbars should accept bindings as a string or an Ember.binding']() { + let FooBarComponent = Component.extend({ + twoWayTestBinding: Binding.from('direction'), + stringTestBinding: 'direction', + twoWayObjectTestBinding: Binding.from('displacement.distance'), + stringObjectTestBinding: 'displacement.distance' + }); + + this.registerComponent('foo-bar', { + ComponentClass: FooBarComponent, + template: 'two way: {{twoWayTest}}, string: {{stringTest}}, object: {{twoWayObjectTest}}, string object: {{stringObjectTest}}' + }); + + this.render('{{foo-bar direction=direction displacement=displacement}}', { + direction: 'down', + displacement: { + distance: 10 + } + }); + + this.assertText('two way: down, string: down, object: 10, string object: 10'); + + this.assertStableRerender(); + + this.runTask(() => set(this.context, 'direction', 'up')); + + this.assertText('two way: up, string: up, object: 10, string object: 10'); + + this.runTask(() => set(this.context, 'displacement.distance', 20)); + + this.assertText('two way: up, string: up, object: 20, string object: 20'); + + this.runTask(() => { + set(this.context, 'direction', 'right'); + set(this.context, 'displacement.distance', 30); + }); + + this.assertText('two way: right, string: right, object: 30, string object: 30'); + + this.runTask(() => { + set(this.context, 'direction', 'down'); + set(this.context, 'displacement', { distance: 10 }); + }); + + this.assertText('two way: down, string: down, object: 10, string object: 10'); + } +}); diff --git a/packages/ember-glimmer/tests/integration/content-test.js b/packages/ember-glimmer/tests/integration/content-test.js index 9189368e568..f732dbeedb5 100644 --- a/packages/ember-glimmer/tests/integration/content-test.js +++ b/packages/ember-glimmer/tests/integration/content-test.js @@ -113,6 +113,22 @@ class DynamicContentTest extends RenderingTest { this.assertInvariants(); } + ['@test it can render undefined dynamic paths']() { + this.renderPath('name', {}); + + this.assertIsEmpty(); + + this.assertStableRerender(); + + this.runTask(() => set(this.context, 'name', 'foo-bar')); + + this.assertContent('foo-bar'); + + this.runTask(() => set(this.context, 'name', undefined)); + + this.assertIsEmpty(); + } + ['@test it can render a deeply nested dynamic path']() { this.renderPath('a.b.c.d.e.f', { a: { b: { c: { d: { e: { f: 'hello' } } } } } diff --git a/packages/ember-htmlbars/tests/integration/binding_integration_test.js b/packages/ember-htmlbars/tests/integration/binding_integration_test.js deleted file mode 100644 index e843893954e..00000000000 --- a/packages/ember-htmlbars/tests/integration/binding_integration_test.js +++ /dev/null @@ -1,146 +0,0 @@ -import Ember from 'ember-metal/core'; -import run from 'ember-metal/run_loop'; -import jQuery from 'ember-views/system/jquery'; -import EmberView from 'ember-views/views/view'; -import { Binding } from 'ember-metal/binding'; -import EmberObject from 'ember-runtime/system/object'; -import { computed } from 'ember-metal/computed'; -import compile from 'ember-template-compiler/system/compile'; -import { runAppend, runDestroy } from 'ember-runtime/tests/utils'; -import { registerHelper } from 'ember-htmlbars/helpers'; - -import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; -import viewKeyword from 'ember-htmlbars/keywords/view'; - -var view, MyApp, originalLookup, lookup, originalViewKeyword; - -var trim = jQuery.trim; - -import isEnabled from 'ember-metal/features'; -if (!isEnabled('ember-glimmer')) { - // jscs:disable - -QUnit.module('ember-htmlbars: binding integration', { - setup() { - originalViewKeyword = registerKeyword('view', viewKeyword); - originalLookup = Ember.lookup; - Ember.lookup = lookup = {}; - - MyApp = lookup.MyApp = EmberObject.create({}); - }, - - teardown() { - Ember.lookup = originalLookup; - - runDestroy(view); - resetKeyword('view', originalViewKeyword); - view = null; - - MyApp = null; - } -}); - -QUnit.test('should call a registered helper for mustache without parameters', function() { - registerHelper('foobar', function() { - return 'foobar'; - }); - - view = EmberView.create({ - template: compile('{{foobar}}') - }); - - runAppend(view); - - ok(view.$().text() === 'foobar', 'Regular helper was invoked correctly'); -}); - -QUnit.test('should bind to the property if no registered helper found for a mustache without parameters', function() { - view = EmberView.extend({ - foobarProperty: computed(function() { - return 'foobarProperty'; - }) - }).create({ - template: compile('{{view.foobarProperty}}') - }); - - runAppend(view); - - ok(view.$().text() === 'foobarProperty', 'Property was bound to correctly'); -}); - -QUnit.test('should be able to update when bound property updates', function() { - MyApp.set('controller', EmberObject.create({ name: 'first' })); - - var View = EmberView.extend({ - template: compile('{{view.value.name}}, {{view.computed}}'), - valueBinding: 'MyApp.controller', - computed: computed(function() { - return this.get('value.name') + ' - computed'; - }).property('value') - }); - - run(function() { - view = View.create(); - }); - - runAppend(view); - - run(function() { - MyApp.set('controller', EmberObject.create({ - name: 'second' - })); - }); - - equal(view.get('computed'), 'second - computed', 'view computed properties correctly update'); - equal(view.$('i').text(), 'second, second - computed', 'view rerenders when bound properties change'); -}); - -QUnit.test('should allow rendering of undefined props', function() { - view = EmberView.create({ - template: compile('{{name}}') - }); - - runAppend(view); - - equal(view.$().text(), '', 'rendered undefined binding'); -}); - -QUnit.test('should cleanup bound properties on rerender', function() { - view = EmberView.create({ - controller: EmberObject.create({ name: 'wycats' }), - template: compile('{{name}}') - }); - - runAppend(view); - - equal(view.$().text(), 'wycats', 'rendered binding'); - - run(view, 'rerender'); - - equal(view.$().text(), 'wycats', 'rendered binding'); -}); - -QUnit.test('should accept bindings as a string or an Ember.Binding', function() { - var ViewWithBindings = EmberView.extend({ - twoWayBindingTestBinding: Binding.from('context.direction'), - stringBindingTestBinding: 'context.direction', - template: compile( - 'two way: {{view.twoWayBindingTest}}, ' + - 'string: {{view.stringBindingTest}}' - ) - }); - - view = EmberView.create({ - viewWithBindingsClass: ViewWithBindings, - context: EmberObject.create({ - direction: 'down' - }), - template: compile('{{view view.viewWithBindingsClass}}') - }); - - runAppend(view); - - equal(trim(view.$().text()), 'two way: down, string: down'); -}); - -} diff --git a/packages/ember-htmlbars/tests/integration/binding_integration_test.js b/packages/ember-htmlbars/tests/integration/binding_integration_test.js new file mode 120000 index 00000000000..a12867e79dd --- /dev/null +++ b/packages/ember-htmlbars/tests/integration/binding_integration_test.js @@ -0,0 +1 @@ +../../../ember-glimmer/tests/integration/binding_integration_test.js \ No newline at end of file